In Tips & tricks from my 4 months at Pythian, I showed how to give a symlink a new target atomically. I wasn’t aware of any module to encapsulate that, so I quickly put together
This module is useful because it eliminates the need to know how to do this safely - simply
CORE::symlink. It creates a temporary symlink (using
File::Tempto get a unique pathname) pointing to your new target, then moves it into place with a
renamecall. On POSIX systems, the rename system call guarantees atomicity.
I put it on PrePAN to get some advice. I have no clue what that’ll do on any non-POSIX systems that have symlinks (if the OS doesn’t do symlinks, I can’t help you). Is a rename call universally atomic? If not, how can I detect those platforms, and provide that atomic guarantee some other way?
I didn’t get any feedback, so I chose to simply release the module. It’s now on CPAN. Enjoy!
Posted: May 26, 2012