Gedit deletes file on samba shares when using a plugin which uses WebKit2
What doesn't work
I use gedit to open an existing text file, modify it and want to save it. It fails with the error:
You do not have the permissions necessary to save the file. Please check that you typed the location correctly and try again.
When I check (ls
or refresh in nautilus), the file is still there.
But there is an inconsistent state
- Server file system:
ls
lists the file andcat file
shows the contents. - Samba mount:
ls
lists the file butcat file
outputscat: file: No such file or directory
.
When I then close gedit without saving changes, the file is removed from directory listing and from the server as well!
What works
- Opening and saving a new (nonexistent) text file on that share
- Without closing gedit, saving it again
- Using another editor like Vim or Atom to edit an existing text file
System
Gedit 3.36.2 on Ubuntu 20.04
Samba implementation: dperson/samba (samba-4.11.8-r0
on Alpine 3.11.6).
Output of mount
(capital strings replaced):
/etc/auto.SERVER on /shares/SERVER type autofs (rw,relatime,fd=6,pgrp=2085,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=45304)
//IP/home on /shares/SERVER/home type cifs (rw,relatime,vers=3.1.1,cache=none,username=USER,uid=1000,forceuid,gid=1000,forcegid,addr=IP,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,rsize=4194304,wsize=4194304,bsize=1048576,echo_interval=60,actimeo=1)
Samba implementation: dperson/samba (samba-4.11.8-r0
on Alpine 3.11.6).
Plugin code
File ~/.local/share/gedit/plugins/test.plugin
:
[Plugin]
Loader=python3
Module=test
Name=Test
Description=Test
File ~/.local/share/gedit/plugins/test/__init__.py
:
import gi
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, Gedit, GObject, WebKit2
class MyPreviewPlugin(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = "MyPreview"
window = GObject.property(type=Gedit.Window)
def __init__(self):
GObject.Object.__init__(self)
def do_activate(self):
self.htmlView = WebKit2.WebView()
self.scrolledWindow = Gtk.ScrolledWindow()
self.scrolledWindow.add(self.htmlView)
self.scrolledWindow.show_all()
panel = self.window.get_side_panel()
panel.add_titled(self.scrolledWindow, "MyPreview", "My Preview")
panel.show()
panel.set_visible_child(self.scrolledWindow)
self.handleTabChanged = self.window.connect("active-tab-changed", self.onTabChangedCb)
def onTabChangedCb(self, *args):
# NOTE the following line causes the error.
# replacing it with `pass` removes the error
self.htmlView.load_html("", "file:///")
Why is active-tab-changed
callback called when saving a file?
Why is it possible that some side panel element can cause the saving process to fail?
Steps to reproduce
Create and active the gedit plugin described above. Close gedit.
container=$(sudo docker run -d --rm dperson/samba -p -r -s "share;/share;yes;no;yes")
ip=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $container)
sleep 1
sudo mount -t cifs -o guest,uid=$(id -u) //$ip/share /mnt
echo "blablub" > /mnt/file
ls -l /mnt
There should be a file file
with write permissions.
gedit /mnt/file
Edit the file and try to save it. The error should be displayed.
When you close gedit now, the file /mnt/file
disappeared.
ls -l /mnt
When you are finished
sudo umount /mnt
sudo docker stop $container