4 ms·
Sometimes you want to use a temp file named ${target_name}.new, then rename it after writing to it -- the point of this is to avoid leaving garbage if you have
by cryptonector 6y ago
Sometimes you want to use a temp file named ${target_name}.new, then rename it after writing to it -- the point of this is to avoid leaving garbage if you have unclean exits, but it requires using flock(2). Even better is to create an unlinked file using O_TMPFILE (Linux-only) and then use linkat(2) and then rename(2) (renameat2(2) doesn't quite support what's needed, and it's a darned shame). If you're doing this in a /tmp/ directory, well, you do have to worry about attacks by other users if you try to do the .new thing.
- asveikau 6y agoWanting a few more details I googled that and found: https://lwn.net/Articles/559147/ https://lwn.net/Articles/559147/ Second time I googled something you mentioned in this thread, eager to know more. This guy filesystems, folks.