Bug 316240 - KSaveFile: Kate/kwrite makes a copy of a file while editing a hard link
Summary: KSaveFile: Kate/kwrite makes a copy of a file while editing a hard link
Status: RESOLVED INTENTIONAL
Alias: None
Product: kdelibs
Classification: Frameworks and Libraries
Component: kdecore (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-06 18:59 UTC by Aleh
Modified: 2015-11-15 16:00 UTC (History)
6 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 Aleh 2013-03-06 18:59:20 UTC
Kate rewrites a hard link of a file with a copy of it, so it will not point to original file.

Reproducible: Always

Steps to Reproduce:
1. Create a hard link for a text file
2. Edit the newly created link via Kate/kwrite
3. Save the changes (i used ctrl+s)
Actual Results:  
We have 2 different files with it's own different contents.

Expected Results:  
The original file and the link with the same content.
Comment 1 Tobias C. Berner 2013-03-09 15:52:54 UTC
I can confirm this bug on FreeBSD 10.0-CURRENT and 
Qt: 4.8.4
KDE Development Platform: 4.10.1
Kate: 3.10.1
Comment 2 Dominik Haumann 2013-03-09 21:00:57 UTC
Again, most certainly a KSaveFile issue: KSaveFile writes to a temporary file and then renames the file, probably turning the hardlink into a normal file.
Comment 3 Christoph Cullmann 2013-03-10 14:16:28 UTC
Generic KSaveFile issue.
Comment 4 David Faure 2013-03-26 14:02:48 UTC
Thiago wrote this in https://codereview.qt-project.org/52059 :

"Who says the effects are undesireable? The hardlink may have been placed there so a backup copy could exist if the file got modified. Think of how Git shares object files between repositories: a hardlink is created and, if the file is modified for any reason (not one of the WORM files), it breaks the hardlink -- COW behaviour."

Dominik, Christoph: OK to close as WONTFIX (or INVALID)?
Comment 5 Christoph Cullmann 2013-03-26 14:41:38 UTC
I would be ok with that, hard links to user editable files are anyway a real corner case.
Comment 6 Martin Nicholas 2013-07-15 08:58:48 UTC
The problem with this is that the link is SILENTLY reomved. A user will have gone to some trouble to create the hard link in the first place and its arrogant to assume that it needs to be broken by any editing.

There needs to be an option within KSaveFile giving choice of saving method:
1. A mv into place, which can be atomic (good) and can be the default.
2. A cp into place, which is not atomic, but preserves any hard link.

Further Observations:
Most people would think it bizarre if editing a symlink generated a second copy of the file.
Editing a file with nano (for example) preserves hard links, see the quotation above.
Comment 7 gnux83 2014-04-30 12:58:28 UTC
*** This bug has been confirmed by popular vote. ***
Comment 8 Nikos Platis 2015-11-15 16:00:53 UTC
I completely agree with comment #6.

I have recently had the need to use hard links for a specific purpose, only to find out that Kate and all the programs that use it destroy my links (without a choice or warning), which is totally unacceptable.