Bug 358457 - QSaveFile: Kate removes a hard link to file when opening a file with several hard links
Summary: QSaveFile: Kate removes a hard link to file when opening a file with several ...
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: general (show other bugs)
Version: 16.04.1
Platform: Arch Linux Other
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
: 376937 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-01-23 23:05 UTC by Laptander
Modified: 2018-08-18 09:14 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Laptander 2016-01-23 23:05:29 UTC
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.
Comment 1 Dominik Haumann 2016-01-26 20:19:35 UTC
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.
Comment 2 Buovjaga 2016-06-30 15:52:57 UTC
Confirmed.

Arch Linux 64-bit
Kate 16.04.2
KDE Frameworks 5.23.0
Qt 5.7
xcb wm
Comment 3 Paul Sommer 2017-02-26 00:09:56 UTC
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?
Comment 4 Dominik Haumann 2017-02-26 16:58:44 UTC
*** Bug 376937 has been marked as a duplicate of this bug. ***
Comment 5 Christoph Cullmann 2018-08-18 09:14:57 UTC
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