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
and you get a drop-in replacement for
CORE::symlink. It creates a temporary symlink (using
File::Temp to get a unique pathname) pointing to your new target, then moves it into place with a
rename call. 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 26th, 2012, by Mike Doherty
Categories: Linux, OS, Perl, Programming, Work
Tags: new-code, Perl, prepan
Comments: 1 Comment.