Skipping hardlinks in a copy

Phil Howard phil-rsync-2 at
Fri Mar 9 16:55:15 GMT 2007

On Thu, Mar 08, 2007 at 01:34:03PM -0800, Sriram Ramkrishna wrote:

| OK, I wasn't aware that you couldn't hardlink a directory to another
| directory.

You're not supposed to be able to.  But some systems allow it in a
restricted manner just for very special issues such as recovery of
an otherwise corrupt filesystem.  Some others might allow it due to
a bug.

Hard linking directories can produce the loops, and this is a major
reason for disallowing them in the normal case.  Another is that an
empty directory with 2 or more links will not appear empty in the
normal manner.  All these things could be worked around, but it is
detrimental to the system to have to do things in such ways.

Sequent Dynix around 1990 or so allowed doing rename(2) simultaneously
on different processors, each naming a different target name, without
proper locking, and it would result in hard links.  I encountered this
with regular files then tested it with directories and it allowed that,
too.  Then the directories could not be removed, even though empty.  I
used the same bug to reverse the process that created them by renaming
the two directories back to one name to get out of the mess.

| OK.  Looks like I just have to deal wtih each cycle I encounter and
| break it.  Joy. :-)

What does "find" for that system do?  If they allow hard links, then
their tools should know how to work around them.

I hope your application doesn't depend on these hard linked directories.

| I'm at a loss then at what I'm looking at.  Maybe it's following
| symlinks and I have not checked the arguments properly.  It might
| be that symbolic links are causing the issue, but in that case it
| doesn't seem to explain why it's taking days to copy a level 0 copy.
| I leaped on the link tree issue, because strace on an rsync was
| showing it going through the same progression of directories.
| I'm going to have to go back and run it again and see if I can
| catch it.

Normally, symlinks to directories are not followed.  I've never seen
rsync or find do that.  I've written a tree recursion function in a
library and it doesn't follow symlinks.

More information about the rsync mailing list