symbolic link cycling

Matthew Seaman m.seaman at infracaninophile.co.uk
Thu May 27 05:03:54 PDT 2004


On Thu, May 27, 2004 at 07:12:02AM -0400, Boucher, Eric wrote:

> Is it possible to know which folders are pointing to each other in a cycle
> manner by doing a find or some other command? I have a backup utility (in
> windows thru samba) which seems to backup redundant files, probably due to
> some symbolic links pointing to each other in cycle. Maybe a shell script
> can do the job? I searched on the internet without good results. I hope that
> my question is clear. Thanks,

The usual solution to this sort of problem is to make your backup
script not chase symlinks at all.  You can't create directory loops
using hard links[1], and usually you would want your backup system to
reproduce the symlinks rather than replacing the link with whatever it
points at.  Most commands you might use to make backups will default
to not following symlinks -- tar(1), find(1)+cpio(1), dump(1),
rsync(1) all work that way be default.  cp(1) defaults to that
behaviour if given the '-R' flag (copy filesystems recursively).

Probably the best way to detect a symlink loop would be to record the
inode number of any directory visited, and then test if the current
directory had been visited before.  Note: you can't do this with
ordinary files, as it's perfectly legitimate for the same file to have
many hard links and so appear in the filesystem in multiple places.

	Cheers,

	Matthew

[1] Unless you have root access to the filesystem, and know quite a
lot about its internals.

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20040527/d8e770ca/attachment.bin


More information about the freebsd-questions mailing list