Bug 158098 - cannot overwrite sshfs mounted files
Summary: cannot overwrite sshfs mounted files
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: file (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-20 15:59 UTC by Stefan Frings
Modified: 2013-03-13 14:13 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Strace log for overwriting a file in KDE 4.10 (2.44 KB, text/x-log)
2013-02-12 09:24 UTC, piotrdz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Frings 2008-02-20 15:59:06 UTC
Version:           4.5.8 (using 3.5.8, Debian Package 4:3.5.8.dfsg.1-7 (lenny/sid))
Compiler:          Target: i486-linux-gnu
OS:                Linux (i686) release 2.6.23.15

I can open text files from sshfs mounted directories but I cannot save them. My workaround is to use the fish protocol. But I prefer sshfs because it runs much more stable.
Comment 1 Stefan Frings 2008-02-20 16:03:52 UTC
Sorry, I forgot to write, that an error message about bad file permissions appears. I assume they are related to the file owner ID. I have a different ID on my notebook than on the file server and I cannot change that situation. After that error message, kwrite lets the original text file unchanged and stores another file with the ending ".part" with the new content.

Obviously, sshfs cannot rename+overwrite a file in one step. Example:

old file: test.txt
temp file: test.txt.part

kwrite tries: rename test.txt.part test.txt

Maybe the solution is to delete the old file before renaming the temp file.
Comment 2 Dominik Haumann 2008-02-22 13:16:40 UTC
If katepart deletes the file all the permissions are gone. Imo, this is not really a kate bug. maybe a permissions problem not even related to kde, of if you are using a kio-slave, then it's maybe a kioslave issue.
Comment 3 Dominik Haumann 2008-02-22 13:19:38 UTC
> ... all the permissions are gone.
This part is probably wrong, as the .part-file is moved then. Not kwrite tries to rename, but kio.
Comment 4 Christoph Cullmann 2008-08-13 21:38:49 UTC
If a problem, then kio
Comment 5 Stefan Frings 2008-09-22 17:49:23 UTC
The problem has been resolved partially. Kwrite can now overwrite existing files on sshfs mounted directories using the menu command Save-As. But It refises to overwrite files using the Save command, then it says: YOu don't have permission to overwrite the file. This is not true, I have that permission.

The problem might be related to the owner ID of that file, which does not exist on my local machine. But the group ID exists and has rw permission.
Comment 6 Jekyll Wu 2011-12-31 02:37:08 UTC
I failed to reproduce the reported problem using KDE SC 4.8 RC1. Is this still a problem for the reporter in recent versions?
Comment 7 Stefan Frings 2011-12-31 09:07:36 UTC
I cannot reproduce the problem anymore with Debian stable, package version of kwrite is 4:4.4.5-2. It works fine now.
Comment 8 piotrdz 2013-02-12 09:22:56 UTC
Unfortunately, it seems this bug is back in KDE 4.10.

I use Arch Linux and I did a system upgrade which upgraded KDE packages from 4.9.5 to 4.10.0. Trying to overwrite a file in mounted sshfs filesystem in Kate, I get an error: "The document could not be saved as it was not possible to write to [file_name]
Check that you have write access to this file or that enough disk space is available."
I can create new files, though - the problem, as in original description, appears only on overwriting.

I tried remounting with "-o idmap=user", which translates permissions to use my UID, but it didn't help. The only fix was to downgrade the packages back to 4.9.5.
Comment 9 piotrdz 2013-02-12 09:24:39 UTC
Created attachment 77190 [details]
Strace log for overwriting a file in KDE 4.10
Comment 10 Christoph Feck 2013-02-19 00:11:19 UTC
Is this issue only reproducible with Kate?
Comment 11 piotrdz 2013-02-21 16:16:38 UTC
I only tried Kate and KDevelop (which uses internally Kate components). I think it is specific to the way Kate writes files, writing first to temporary file and then renaming it.

I've found a better workaround: mounting sshfs with "-o workaround=rename". There seems to be a problem with rename() system call, which normally doesn't work for sshfs, but is patched somehow with this workaround option. But it has its own disadvantages (e.g. files saved with this option change permissions to include exec rights: 775).

Looking at strace from 3.9.5, I see that previously a file was simply saved in place, not via a temporary file. I think there should be a sort of fallback mechanism on this older method, if renaming the temporary file doesn't work. Or there could be a configuration option to choose the desired behavior. Either way, IMO relying on rename() to work in all cases is a bad choice ("man 2 rename" lists more scenarios where it could fail).
Comment 12 David Faure 2013-02-22 23:12:46 UTC
That's not specific to kate, it's the KSaveFile/QSaveFile approach, which is the only way to ensure that files don't get corrupted when the partition is full, or the app crashes while writing out the file.
rename() has to work (and has to be able to replace existing files), that's the expected POSIX behavior of rename(). Why doesn't this work for sshfs?
Sounds like a sshfs bug to me.
Comment 13 piotrdz 2013-02-23 10:59:39 UTC
After looking through several forums and mail lists, I found this thread: http://www.mail-archive.com/macfuse-devel@googlegroups.com/msg00557.html

It seems that rename() is supported by sftp protocol, but it has different semantics than the POSIX version: if renaming to existing file, it will fail with EPERM. Sshfs with "-o workaround=rename" works around this by using temporary files and unlinking the existing file. This temporary file is created with those wrong permisssions, but I think I can live with that.

Well, in that case, I withdraw my comments: it is not a bug in KDE. Thanks for your time anyway.
Comment 14 Cristóvão Sousa 2013-03-13 14:13:18 UTC
> I've found a better workaround: mounting sshfs with "-o workaround=rename".
> There seems to be a problem with rename() system call, which normally
> doesn't work for sshfs, but is patched somehow with this workaround option.
> But it has its own disadvantages (e.g. files saved with this option change
> permissions to include exec rights: 775).

As a workaround for the exec rights disadvantage one can use the noxec option:
"sshfs -o workaround=rename -o noexec"