It is not possible to save a file in Kate in, let say, /usr/share/ unless you give ownership of the directory to the user instantiating kate or give plain 777 permission to the directory. Saving a file should take into account if a) the file is accessible and b) the file have the correct write permission. All other editors can save that file, but kate give a nice. "The document could not be saved, as it was not possible to write to /usr/share/awesome/lib/awful/widget/common.lua. Check that you have write access to this file or that enough disk space is available." This is obviously wrong, because both conditions are ok. I tried with many different files and folder/ Reproducible: Always Steps to Reproduce: 1. su - 2. mkdir /tmp/katetest 3. touch /tmp/katetest/file.txt 4. chmod 777 /tmp/katetest/file.txt 5. exit 6. kate /tmp/katetest/file.txt 7. ctrl+s Actual Results: An error Expected Results: The file being correctly saved I give "major" severity because it create security flaw when a user have to give more permissions than necessary to do a basic operation.
This is because we use KSaveFile in Kate::TextBuffer::save(): KSaveFile saveFile (filename); if (!saveFile.open()) return false; KSaveFile first saves under a different name, and finally renames on successful safe. Obviously, since the directory owner is root with permissions rwxr-xr-x, the temporary file cannot be created. Possible solutions: 1. KSaveFile should handle this special case (save to another folder, then move; or overwrite directly) 2. Kate Part needs to work around this.
(In reply to comment #1) > Possible solutions: > 1. KSaveFile should handle this special case (save to another folder, then > move; or overwrite directly) > 2. Kate Part needs to work around this. Why not to use /var/tmp/kdecache-$USER directory for temporary file and then overwrite the original file from it?
There is also another problem with it, described in this bugreport: https://bugs.kde.org/show_bug.cgi?id=316234
>Why not to use /var/tmp/kdecache-$USER directory for temporary file and then overwrite the original file from it? /tmp is not on the same device, so saving it there by default would end up requireing copies done to the original directory. A power loss during this would risk damaging date. A "move" operation, doesn't copy content, it just change the pointer. I guess save&move in the right directory is right, but not perfect.
Emmanuel is correct: Saving to tmp may be on another device. In that case, we could directly overwrite the file as well, since whether Kate or the cp-process damages the data does not make a difference...
*** Bug 316234 has been marked as a duplicate of this bug. ***
OK, implemented "overwrite directly", as a fallback solution for this to work. https://codereview.qt-project.org/52059
Git commit 4c59b6a716ca750e024b910f28e0263d07dae2f1 by David Faure. Committed on 04/04/2013 at 19:53. Pushed by dfaure into branch 'KDE/4.10'. KSaveFile: add setDirectWriteFallback(). This is a backport of https://codereview.qt-project.org/52059 which does the same in QSaveFile for Qt 5.1 M +48 -26 kdecore/io/ksavefile.cpp M +34 -0 kdecore/io/ksavefile.h M +84 -0 kdecore/tests/ksavefiletest.cpp M +3 -0 kdecore/tests/ksavefiletest.h http://commits.kde.org/kdelibs/4c59b6a716ca750e024b910f28e0263d07dae2f1
Git commit 2aaf9df6582f3be1c6eefd857f9c5f8f2d95a93b by Christoph Cullmann. Committed on 04/04/2013 at 22:42. Pushed by cullmann into branch 'master'. allow fallback for ksavefile allow save in dirs without write rights M +13 -0 part/buffer/katetextbuffer.cpp http://commits.kde.org/kate/2aaf9df6582f3be1c6eefd857f9c5f8f2d95a93b
*** Bug 320142 has been marked as a duplicate of this bug. ***
*** Bug 318462 has been marked as a duplicate of this bug. ***