Bug 402363 - File mode always set to 0600 when saving changes
Summary: File mode always set to 0600 when saving changes
Status: RESOLVED FIXED
Alias: None
Product: kompare
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Kompare developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-19 20:05 UTC by John Baldwin
Modified: 2021-07-21 10:17 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 21.07.90


Attachments
libkomparediff2 patch to set file permisions on copy (1.15 KB, patch)
2019-12-29 07:58 UTC, Terry Barnaby
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John Baldwin 2018-12-19 20:05:05 UTC
SUMMARY

When using kompare to apply changes from one file to another, the updated file's permissions are reset to 0600 (presumably you are creating a new file with 0600 and renaming it on top of the old file instead of opening and rewriting the existing file and this is losing the existing permissions as a result?).  This seems like a regression from kompare in KDE 4.

STEPS TO REPRODUCE
1. echo foo > foo
2. echo bar > bar
3. ls -l foo bar
-rw-r--r--  1 john  john  4 Dec 19 11:58 bar
-rw-r--r--  1 john  john  4 Dec 19 11:58 foo
4. kompare foo bar
<space> to apply delta
Ctrl-Q to quit and save
5. ls -l foo bar
-rw-------  1 john  wheel  4 Dec 19 11:58 bar
-rw-r--r--  1 john  john   4 Dec 19 11:58 foo

OBSERVED RESULT

-rw-------  1 john  wheel  4 Dec 19 11:58 bar

EXPECTED RESULT

-rw-r--r--  1 john  wheel  4 Dec 19 11:58 bar

SOFTWARE/OS VERSIONS
FreeBSD: 12.0-PRERELASE
KDE Plasma Version: 5.12.7
KDE Frameworks Version: 5.52.0
Qt Version: 5.11.2
kompare: 18.08.3

ADDITIONAL INFORMATION
Comment 1 szecsodimlaszlo 2019-05-23 09:07:09 UTC
I have the same critical issue.

- Arch Linux
- KDE / Kompare 19.04
Comment 2 Terry Barnaby 2019-12-29 07:58:21 UTC
Created attachment 124765 [details]
libkomparediff2 patch to set file permisions on copy

This is a patch that sets the file permissions on file_copy to be the same as the original file. This may not be the correct way of doing this. I can't find any documentation on what the permissions = -1 argument to KIO::file_copy is actually supposed to do. This setting "may" have been meant to keep the files permissions unchanged but it seem to set them to 0600. Maybe someone who knows how KIO is supposed to work can answer this ?
Comment 3 Terry Barnaby 2019-12-29 08:02:12 UTC
Forgot to say, this patch is to the libkomparediff2-19.04.3 library that kompare uses.
Comment 4 Kevin Kofler 2019-12-29 11:15:22 UTC
> This is a patch that sets the file permissions on file_copy to be the same as the original file.

Looks good to me. Do you have git write (push) access to the KDE repositories? Or shall I push it?

> This may not be the correct way of doing this. I can't find any documentation
> on what the permissions = -1 argument to KIO::file_copy is actually supposed
> to do. This setting "may" have been meant to keep the files permissions
> unchanged but it seem to set them to 0600. Maybe someone who knows how KIO is
> supposed to work can answer this ?

The documentation:
https://api.kde.org/frameworks/kio/html/namespaceKIO.html#ad7e9c41cdcc6255c56dc2e32a7442995
says:
"May be -1. In this case no special permission mode is set."
which I would interpret as meaning it just uses the default umask of the destination file system. (At most, some KIOslaves might attempt to copy the permissions of the SOURCE file, but it definitely does not mean retaining the permissions of an existing destination file that is being overwritten.)
Comment 5 Terry Barnaby 2019-12-29 11:30:10 UTC
Hi Kevin, no I don't have git write permissions. Feel free to push it if you think it is valid (I have very little knowledge on how the KDE KIO system works).

Terry
Comment 6 szecsodimlaszlo 2020-07-09 09:06:54 UTC
Any progress on this bug?
Comment 7 Emmett Culley 2020-07-09 23:06:33 UTC
Here we are in Fedore 32 and this is still a serious inconvenience.  How can we find out where this issue is in KDE priorities?
Comment 8 szecsodimlaszlo 2021-07-21 06:15:38 UTC
Another year has past… Is there any progress on this bug?
Comment 9 Kevin Kofler 2021-07-21 10:17:09 UTC
Git commit 99b1d14756279c6cb3cb4df6027585130d17205e by Kevin Kofler.
Committed on 21/07/2021 at 10:16.
Pushed by kkofler into branch 'release/21.08'.

Set correct file mode when saving changes (#402363)

src/komparemodellist.cpp (KompareModelList::saveDestination): Get
permissions of existing file and copy temporary file with the same
permissions.

Patch by Terry Barnaby.
FIXED-IN: 21.07.90

M  +9    -1    src/komparemodellist.cpp

https://invent.kde.org/sdk/libkomparediff2/commit/99b1d14756279c6cb3cb4df6027585130d17205e