2008/03/24

Fix Absolute Symbolic Links from tar or rsync SNAFU

Tar will strip leading slashes from sym links (if you don't use -P), as will rsync in some situations (for example, with chroot=true). This can put you in a world of hurt. Here are some tips for how to fix it.
  • This one won't work for a couple of reasons; first, it can't distinguish between intended relative paths and accidental relative paths; also, cut won't work if any files that have a different character length in any fields of the ls output, such as ownership or date (there's a way to merge whitespace that escapes me, not fmt or pr, but something :
    • find . -type l -print0 | xargs -0 ls -laQ | grep ' -> \"relative/path/stuff'| cut --complement -d " " -f 1-8 | sed -e 's/ -> \"/\;\"\//g' | awk -F\; '{ print "ln -sf " $2 " " $1 }' > fix_symlinks
  • How about this:
    • find . -type l -printf 'ln -sf "/%l" "%p"\n' | grep "\"/accidental/relative/path" > fix_symlinks
    • check the fix_symlinks for things that you actually don't want to change.
    • . ./fix_symlinks
There has got to be a more elegant way to do this. *sigh* if my perl skills were half-decent, it'd probably be a breeze.

Also, note the "symlinks" command in the "symlinks" package.



No comments: