Whenever I use mcedit
to edit a file that is hard linked somewhere and I want to save the file, the editor asks me if I want to remove the hard links. Is that common behavior on Linux or is mcedit
"special" in doing so? Why would regular applications (not fsck or other admin tools) care about hard links?
Why does mcedit recommend removing hardlinks when saving a file
filesystemshard link
Best Answer
When you want to modify a file, you have two options, each with its benefits and drawbacks.
Mcedit is asking you which strategy to choose. Strangely though, mcedit's default strategy, for files with a single directory entry, is to truncate the existing file, putting your data at risk. Only when the safe strategy would break a hard link does it give you the opportunity to use it. You can change this in the “Edit save mode” dialog from the Options menu: “quick save” means overwrite, “safe save” means save to a temporary file then rename. When safe mode is chosen, you don't get a choice not to break symbolic links.
(Observations made on mc 4.8.3. If this is still the case in the latest version, consider reporting it as a design bug — “safe mode” should be the default, and you should get an option not to break hard links in that case.)
Good editors such as Vim or Emacs let you choose the default strategy.