Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It is not really a bug, just counter intuitive behavior. Their example is somewhat contrived, usually this will just manifest in something being broken.

If you use an editor with safe saves this might not even happen because that works by saving to a temp file and doing an atomic swap, and unlinking the old file. In that case, I believe the script should continue as written, because the fd should point to the unlinked file. I believe vim does this by default, for example.



Using rename() does this for you. It's actually guaranteed to preserve the contents of the old file for any process still having it open while atomically letting any future process only see the new file.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: