2

Usually, applications perform atomic saves either by renaming the old file and writing the new file in place, or by writing a temp file and then replacing the old file with the new temp file. Which of these does emacs do? I found this link to a patch discussion, but I don't understand what is going on.

0
2

The answer is that it depends on all kinds of factors.

First, note that "renaming the old file and writing the new file in place" is not atomic.

Emacs can save in various ways:

  • rename old file + write in place (non-atomic, breaks links).
  • don't rename, write over existing file (non-atomic, doesn't break links).
  • write to new file, then rename it (atomic, breaks links).

Note that "break links" also implies that the new file may have different permissions/owner/...

In most cases, Emacs will use the second approach (in order to preserve links and permissions). But if it needs to make a backup of the file (according to make-backup-files), then it will often use the first approach (where the rename is used to create the backup), although this depends on backup-by-copying (as well as other variables with names that start with backup-by-copying-when-) as well as file-precious-flag and break-hardlink-on-save.

1
  • Good question, good answer. See also the Emacs manual, node Backup and the Elisp manual, node Making Backups. – Drew May 7 '16 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.