So ideally I'm looking for a way to rsync an entire directory of files
(recursively) and each time a broken symlink is found, resolve it by
changing where it points.
For example is a symlink is broke and points to /usr/local/foo, change
it to /real_source/usr/local/foo.
Do it in 2 steps?
1) rsync
2) find . -type l | while read ln ; do
D=$(readlink "$ln")
[ -e "$D] || ln -sf /real_source/"$D" "$ln"
done
Some versions of 'find' offer extra help, for example
find . -type l ! -xtype l | xargs....
will find broken links rather better (but not perfectly). Then there are
the standard warnings about newlines etc embeded in filenames. However as
you say these are your own files we can probably not worry about them.
From the manpage of rsync:
-l, --links copy symlinks as symlinks
-L, --copy-links copy the referent of symlinks
Would you consider the -L option ?
Yeah I've looked into that. The problem is that I am going to be
copying broken links so I need to intervene each time and modify the
link itself.