Bug 217342 - saving to a sftp-url resets file attributes
Summary: saving to a sftp-url resets file attributes
Status: RESOLVED NOT A BUG
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: SFTP (other bugs)
Version First Reported In: 18.04.3
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Andreas Schneider
URL:
Keywords:
: 218099 336819 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-12-04 15:57 UTC by Robert Schulz
Modified: 2018-09-03 05:50 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Schulz 2009-12-04 15:57:54 UTC
Version:           3.3.1 (using KDE 4.3.1)
Compiler:          gcc 4.4.1 ? 
OS:                Linux
Installed from:    openSUSE RPMs

when saving files using an sftp url, the file attributes will be reset.

Example how to retest this:

nicht gefunden ivr@schulz:~/.hfn> touch /tmp/otto 
ivr@schulz:~/.hfn> ls -l /tmp/otto
-rw-r--r-- 1 ivr users 0  4. Dez 15:52 /tmp/otto 
ivr@schulz:~/.hfn> chmod a+x /tmp/otto 
ivr@schulz:~/.hfn> ls -l /tmp/otto
-rwxr-xr-x 1 ivr users 0  4. Dez 15:52 /tmp/otto 
ivr@schulz:~/.hfn> kate sftp://localhost/tmp/otto
QThreadStorage: Thread 0x609940 exited after QThreadStorage 2147483636 destroyed ivr@schulz:~/.hfn> ls -l /tmp/otto
-rw-r--r-- 1 ivr users 0  4. Dez 15:53 /tmp/otto ivr@schulz:~/.hfn>

I did nothing on the file otto, only pressed "Ctrl-S" to save.

(Which is another Bug -- since kate should not write an unchanged file!)
Comment 1 Matthew Woehlke 2010-01-13 01:38:33 UTC
> (Which is another Bug -- since kate should not write an unchanged file!)

Not necessarily, since the file may have been changed or deleted on disk. (With a local file you are usually notified of this, but with a remote file you may not be.)

Anyway, I was just noticing this as well (in yesterday's trunk), though I'd suspect the bug really lies in KIO (maybe even libssh?) and not kate.
Comment 2 Matthew Woehlke 2010-01-13 21:14:45 UTC
*** Bug 218099 has been marked as a duplicate of this bug. ***
Comment 3 Elliott 2010-02-13 02:32:46 UTC
I also am experiencing this on Opensuse 11.2 (KDE 4.3.5, Kate 3.3.5). Are there any workarounds? I found the local temporary copy kate saves and it has permissions of 600. The original files have 666 but once saved they become 644. Changing the permissions on the temp file has no effect.
Comment 4 Ben Adler 2010-10-16 13:29:44 UTC
Still present in Version 3.5.69, and still very annoying, basically makes it impossible to collaborate with others in the same remote dir.

I could probably work around this with some acl-magic, but thats even more annoying.

How does the mechanism work? Is the file created locally on saving and then transferred to remote using sth. like kfm-client? If yes, is is possible to maybe set a umask to get a more writeable temp-file, and have permissions preserved when its being copied to remote?

Where in the architecture can this bug be fixed?
Comment 5 Thomas Fischer 2010-10-19 13:04:24 UTC
A quick check revealed the following information: The SFTP protocol is implemented in kdebase-runtime/kioslave/sftp/kio_sftp.cpp. If you go into function void sftpProtocol::open(...), there is a line as follows (at least in my KDE 4.4.5 sources):
mOpenFile = sftp_open(mSftp, path_c.constData(), flags, 0644);

This is the moment, where the existing file is replaced with the uploaded data in a new file (same filename though) and reset permissions.

The KDE coding wizards should have a word here, too, but my suggestion would be to check the attributes (including permissions) if the file already exists and use the retrieved bit mask instead of just 0644.
Comment 6 JJ Noe 2011-05-20 11:04:12 UTC
Very bad!
This makes Kate useless for me.
Is there any solution?
Thomas Fischer's suggestion sounds good.
Comment 7 Christoph Cullmann 2011-06-25 11:47:40 UTC
Anyway, this is a kio issue.
Comment 8 Christoph Feck 2014-08-16 12:53:42 UTC
*** Bug 336819 has been marked as a duplicate of this bug. ***
Comment 9 Andreas Schneider 2014-08-20 09:03:55 UTC
Well, we actually only set permissions if the application tells us to create the file! So why is the editor setting O_CREAT.

The code looks like this:

if (flags & O_CREAT) {
    mOpenFile = sftp_open(mSftp, path_c.constData(), flags, 0644);
} else {
    mOpenFile = sftp_open(mSftp, path_c.constData(), flags, 0);
}

You have to understand that if I add code to first check if the file exists and we overwrite a file and should reuse the permission. I have a additional roundtrip for each file, which significantly slows down copying a lot of files.
Comment 10 Andreas Schneider 2018-09-03 05:50:20 UTC
This looks more like an old kate bug.