Create new text files with umask applied
ClosedPublic

Authored by abika on Feb 24 2019, 4:01 PM.

Details

Summary
  • Panel: Clean code for creating new text file

And use global actions for creating new text file and directories in panel
context menu.

  • Panel: Create new local text files directly with QFile

Umask is applied.

Diff Detail

Repository
R167 Krusader
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
abika requested review of this revision.Feb 24 2019, 4:01 PM
abika created this revision.
abika added a subscriber: Krusader.
nmel added a subscriber: nmel.Feb 25 2019, 6:49 AM

Refactoring code is fine, however setting 644 unconditionally introduces a security issue. The permissions for new files should follow umask setting. Otherwise users may unintentionally share their new files with other users.

Since KIO::CopyJob::setDefaultPermissions does not work and all this KIO mambo jumbo is actually needed only for non-local FS, should we split this code and handle file creation for local and non-local files differently? I haven't checked yet, but I guess QFile should be able to handle umask correctly. If not, there are bunch of other ways to create a local file.

abika updated this revision to Diff 53075.Mar 3 2019, 7:05 PM
  • SQUASH_ME Panel: Create new local text files directly with QFile
abika added a comment.Mar 3 2019, 7:07 PM

You're right Nikita. I changed it now so that local files are created with QFile. Umask is applied here.

Actually the code belongs into the FileSystem package, but thats a bigger change I'll eventually do later.

abika retitled this revision from Set permissions of new text files to 644 (-rw-r--r--) to Create new text files with umask applied.Mar 3 2019, 7:16 PM
abika edited the summary of this revision. (Show Details)
nmel added a comment.Mar 4 2019, 7:44 AM

Alex, it looks good now - thanks! Let me test it and I'll get back to you in a few days.

nmel accepted this revision.Mar 7 2019, 6:53 AM

Tested with various umasks and local / remote fs - works nicely. Please don't forget to fix the build (and possibly, the commit messages) before merging. Thanks!

krusader/Panel/panelfunc.cpp
515

code suggestion: return here and on line 524 could be combined into a single return inside the parent if

520

Doesn't build: missing semicolon.

This revision is now accepted and ready to land.Mar 7 2019, 6:53 AM
abika marked an inline comment as done.Mar 8 2019, 7:45 PM

Thanks! Landed (Hope this revision will close itself).

krusader/Panel/panelfunc.cpp
515

I think its more clear with two returns.

Closed by commit R167:dce5c5057c85: Merge branch 'my-new-file-permissions' (authored by Alexander Bikadorov <alex.bikadorov@kdemail.net>). · Explain WhyMar 8 2019, 8:21 PM
This revision was automatically updated to reflect the committed changes.