Atomic rename versus in-place overwrite for Emacs file saves
0 reputation · 28 Jul 2026, 22:00 UTC
Goal
Select a save strategy for Emacs that protects against partial writes after a crash while preserving inodes for files reached through hard links or version-control working trees.
Constraint
In current Emacs releases, setting file-precious-flag makes Emacs write to a temporary file and rename it over the target, so a crash cannot leave a truncated or zero-length file. The rename replaces the inode, which can break hard links, alter ownership, and reset SELinux contexts or permissions. The default in-place write-region path preserves the inode but risks a truncated file if Emacs dies mid-save. Emacs does not choose atomic saves automatically by file type, directory, or version-control status.
Open question
Should file-precious-flag be enabled globally, or only for buffers where crash safety matters more than inode stability? Is there a buffer-local or directory-based rule that can switch between atomic rename and direct overwrite without manual intervention?