News for hackers. Stuff that matters.
Re:Files Are Hard by ploxiln on Sunday December 13, 2015 @12:16PM (#10726953)
I'm surprised rename() wasn't mentioned in the article, it's a well known technique to atomically update a file, which is very practical for small-ish files.

Note that in the general case, you should fsync() the temporary file before you rename() it over the original - but ext3 and ext4 in writeback mode added a heuristic to do that automatically, because ext3 in the default ordered mode would effectively do that and many applications came to assume it.

Re:Files Are Hard by drudru11 on Sunday December 13, 2015 @09:41PM (#10729132)
rename is atomic, but it is not guaranteed to be durable. In order for rename to be durable, I've learned that you have to fsync the parent directory.

I was saddened when I learned this. I used to use this old trick for a lot of my systems. I learned it from reading the code of old well-written unix systems programs.