News for hackers. Stuff that matters.
Re:Dotfile madness by notyourday on Saturday February 02, 2019 @02:08PM (#19064958)
If you do not rename files while holding their open file descriptors there's no guarantee that you are renaming the file you just wrote to.
Re:Dotfile madness by JdeBP on Saturday February 02, 2019 @06:21PM (#19066523)
There is no guarantee of that if one does retain the open file descriptor.
Re:Dotfile madness by notyourday on Monday February 04, 2019 @11:26AM (#19077604)
before rename:

fstat the fd, get st_dev and st_ino.

rename

stat the new name. Compare st_dev and st_ino.

If the value matches, you renamed the right file. If it does not match, you renamed a wrong file. Without holding the fd, it is impossible to know if it is the right file.

Re:Dotfile madness by JdeBP on Monday February 04, 2019 @11:34AM (#19077673)
"you renamed a wrong file" shows that "there's no guarantee that you are renaming the file you just wrote to".
Re:Dotfile madness by notyourday on Monday February 04, 2019 @11:38AM (#19077704)
In this case you know that you renamed a wrong file. In the close before rename you do not know that you have renamed a wrong file.
Re:Dotfile madness by JdeBP on Tuesday February 05, 2019 @06:16AM (#19084304)
Knowing that something bad happened after the fact is not the same as your idea that there's a guarantee that something bad will not happen.