It is impossible to edit files that have more than one hard link. Kate simply deletes hard links and saved files becomes actually different files. Reproducible: Always Steps to Reproduce: 1. Make an empty file touch 1.txt 2. Make a hard link to it ln 1.txt 2.txt 3. Ensure that files are hard linked ls -l {1..2}.txt -rw-r--r-- 2 ... 1.txt -rw-r--r-- 2 ... 2.txt 4. Open 1.txt in Kate and edit it, then save. 5. Check if files are hard linked now ls -l {1..2}.txt Actual Results: -rw-r--r-- 1 ... 1.txt -rw-r--r-- 1 ... 2.txt Expected Results: -rw-r--r-- 2 ... 1.txt -rw-r--r-- 2 ... 2.txt Kate even do not give any warning about such behavior.
I am pretty sure this is because of using QSaveFile. Essentially, we save the data to a new file and then rename it on success. This way, we avoid data corruption at the expense of this misbehavior.
Confirmed. Arch Linux 64-bit Kate 16.04.2 KDE Frameworks 5.23.0 Qt 5.7 xcb wm
A suggestion: Direct write would solve that hard link problem at the cost of possible data loss. Why not doing it this way?: Whenever Kate edits a file that is hardlinked it makes a copy of that file before writing the new content directly into that file. Couldn't be that hard to archive. Could it?
*** Bug 376937 has been marked as a duplicate of this bug. ***
Remove QSaveFile in favor of plain old file saving Summary: Rationale: for many use cases that e.g. have acls, complex other extended attributes, static links e.g. the rename() doesnt do the trick it should other ways would be start to add workarounds to all cases, which is hard, e.g. if that is something shared via SMB... Test Plan: make && make test Reviewers: dhaumann, dfaure Reviewed By: dhaumann, dfaure Subscribers: dfaure, kwrite-devel, kde-frameworks-devel Tags: #kate, #frameworks Differential Revision: https://phabricator.kde.org/D14890