in reply to Re: POSIX::S_ISDIR() with $stat->mode values from Windows vs. Linux
in thread POSIX::S_ISDIR() with $stat->mode values from Windows vs. Linux

Alexander talked enough about symlinks that I want to add this caution on both symlinks and hardlinks to the thread:

If you write to existing files other than append-without-backup, and there's the tiniest risk of a user trying to symlink or hardlink that file: explicitely specify how you write out the file. Funny things happen: E.g. sed -i.bak or perl i.bak and that patch on Fedora recently being removed: changing sed's semantics wrt symlinks and surprising everyone.

date > 1; ln -s 1 2; perl -i.bak -lpe '' 2; ls -l [12]* # enjoy

So at the very least, document how and when you're breaking symlinks or hardlinks on writing. Or not breaking them. Which might be just as bad.

cu
Peter

Footnote: -d _ reuses the previous stat, as Alexander writes, just -d does a new stat using $_. So this an an example of terseness being possibly more costly in both debugging time and runtime :).

  • Comment on Re^2: POSIX::S_ISDIR() with $stat->mode values from Windows vs. Linux
  • Download Code