GNOME Bugzilla – Bug 616645
Renaming a file through Samba overwrites existing one
Last modified: 2011-09-19 11:48:18 UTC
Using Ubuntu 9.10, filed a bug on Launchpad (https://bugs.launchpad.net/ubuntu/+source/samba/+bug/382117) but seems to be upstream bug. When mounting a Samba share with Nautilus and renaming a file in it, it doesn't check if the name already exists and overwrites any existing one without warning. I.e. I have two files "file1" and "file2" on my Samba share, I rename "file2" to "file1": the original "file1" is lost forever. As specified in the Ubuntu bug report, the same behaviour happens with the mv command (both in local and through SSH) but not with a remote folder mounted through SSH with Nautilus. Seems that the bug has been traced to gvfs by the Ubuntu developers (I originally filed it under Samba).
I can confirm this behavior for gvfs-1.8.2.
Confirming, not nice. I guess we would have to do one more stat before real smbc_rename(). Interesting enough the libsmbclient documentation talks about EEXIST error that should be returned but it's not.
Created attachment 195085 [details] [review] proposed patch Always stat the destination before doing rename. This brings one new string for translation, commit after upcoming tarball. TODO: test overwrites on file copy/move
commit 62d2a521df6a7adf8a1dc9598e81947a56c9f3b9 Author: Tomas Bzatek <tbzatek@redhat.com> Date: Tue Aug 30 17:43:09 2011 +0200 smb: Always check for existing file on rename Libsmbclient reports no error when target file or directory exists and overwrites target file. https://bugzilla.gnome.org/show_bug.cgi?id=616645
It would seem that the correct fix is to libsmbclient. Working around a SAMBA bug in GVFS is like putting a bandaid over an infected wound. Has anyone opened a bug report with SAMBA? If in the future libsmbclient gets fixed to emit EEXIST, GNOME will be stuck doing redundant checks that slow things down and lead to confusion. I therefore recommend reverting http://git.gnome.org/browse/gvfs/commit/?id=62d2a521df6a7adf8a1dc9598e81947a56c9f3b9 and pushing SAMBA to fix their bug.
Yes, correct way would be to fix libsmbclient. With tons of other things that we have workarounds for. And then you would have to make gvfs dependent on that new version. From my experience many distributors are rather conservative in samba version and we would like to have Gnome running there, thus we should support older versions. Think of jhbuild for example.