Hacker News new | ask | show | jobs
by ataylor284_ 974 days ago
Moving files to backup instead of copying is better. First, the file modification dates remain meaningful. When a backup is made, the backup file has a last modified date of when it was last changed and the new copy has the current time. It is also reversible if creating the new file fails for some reason. The backup file can moved back to the original location with a single file system operation and retains the right modification date.

It's also more robust in case of errors. Emacs can write new data to a temp file, confirm it succeeded then rename working to backup and new to working. You never have a situation where the working or backup file ends up half written.

2 comments

Yea, this is a detail that Emacs gets right and a lot of other programs fail at. I really recommend not setting `backup-by-copying` because it introduces extra risks. Of course, I also recommend that every computer have a UPS and ECC ram. Defense in depth!
wonder if copying preserving timestamp is possible? best of both worlds?
Posix systems, at least, allow a file's timestamps to be set with utime(2) and related system calls, but a problem with this is that utime with an arbitrary time is not permitted in all situations where writing to a file is possible. Backing up those files would either need a separate strategy or have inconsistent behavior.