4 ms·
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. I
by notyourday 8y ago
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.
- JdeBP 8y ago"you renamed a wrong file" shows that "there's no guarantee that you are renaming the file you just wrote to".
- notyourday 8y agoIn 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.
- JdeBP 8y agoKnowing 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.