Re:Things UNIX can do atomically
by bretthoerner on Wednesday January 06, 2010 @01:44PM
(#1035367)
> something I didn't know about and that the manpage is silent on
It's specific to GNU Coreutils mv(1).
To change a symlink I use:
ln -snf NEW_SOURCE TARGET
Which works fine, but is still not atomic. To be clear, saying something is "atomic" means that there is no way for another process to see the process in an intermediate state (in the example in the article: a missing or incorrect symlink to a deployed web application). Underneath the hood, the /bin/ln program still needs to call unlink() on the path first, so there is a short period of time during which the desired link isn't present. So software written to assume that the link is always valid (for example, because its author was told that the update was atomic) will have hidden bugs.
This kind of tool merely runs really fast. The race condition is still there.
I never said it was atomic ;-) just that i use that method rather than mv.
I mainly use it when i'm updating apps or SDks to newer versions and want to keep the old ones around just in case.
That doesn't mean this trick is useless, but calling it "atomic" is wrong, and opens up the possibility of bugs (likely security holes, even) if someone actually needs atomicity.