Traversing symbolic links ...

M

martin

Hi,I have been reading the postings on use of 'find' for traversing
directories with symbolic links, and there does not seem to be an
agreement if 'find' does follow all the actual directories and captures
files without falling into an infinite loop.

I am wondering if there is a concensus on this, is there any sample
scripts for this, or is use of "'find" for following symbolic links is
not %100 realiable and safe (loop free). Thanks. Martin
 
M

Mahesh Asolkar

martin said:
Hi,I have been reading the postings on use of 'find' for traversing
directories with symbolic links, and there does not seem to be an
agreement if 'find' does follow all the actual directories and captures
files without falling into an infinite loop.

I am wondering if there is a concensus on this, is there any sample
scripts for this, or is use of "'find" for following symbolic links is
not %100 realiable and safe (loop free). Thanks. Martin

Along with postings on the subject, did you also look at the following?

perldoc File::Find

or

http://search.cpan.org/~nwclark/perl-5.8.8/lib/File/Find.pm

The document does specify options 'follow', 'follow_fast',
'follow_skip' and 'dangling_symlinks' that allow you to take variety of
approaches regarding symlinks.

HTH,
Mahesh
 
M

martin

Hi Mahesh,

Thanks, I read parts of the the exerpt from perldoc in one of the
postings. To me it seems that all options below point to the safest way
to go is to use simply "follow" which could take longer and more
resource intensive but not potentially dangerous which is mentioned to
be the case for "symlinks". It just seems too many options and I am
wondering what is best for a filesystem of potentially several thousand
files to use.
Also should one "lock"the file system so to speak briefly to prevent
some of the dangers while directories are being traveresed, in a way to
catch a snapshot of the system in a frozen state before links could be
potentially modified?

Basically I need to be sure I capture all the files and resources to do
this is not my concern but the comprehensiveness and accuracy of the
file listings and physical paths captured after the symbolic link
traversing and expansion is done. I am new to Perl and all this options
seem a bit confusing and require experimentation, I believe to see
really which one is the safest and surest and most exhaustive one.

thanks. martin

=item C<follow>

Causes symbolic links to be followed. Since directory trees with
symbolic
links (followed) may contain files more than once and may even have
cycles, a hash has to be built up with an entry for each file.
This might be expensive both in space and time for a large
directory tree. See I<follow_fast> and I<follow_skip> below.
If either I<follow> or I<follow_fast> is in effect:


=item C<follow_fast>

This is similar to I<follow> except that it may report some files more
than once. It does detect cycles, however. Since only symbolic links
have to be hashed, this is much cheaper both in space and time. If
processing a file more than once (by the user's C<wanted()> function)
is worse than just taking time, the option I<follow> should be used.

This is also a no-op on Win32.


=item C<follow_skip>

C<follow_skip==1>, which is the default, causes all files which are
neither directories nor symbolic links to be ignored if they are about
to be processed a second time. If a directory or a symbolic link
are about to be processed a second time, File::Find dies.

C<follow_skip==0> causes File::Find to die if any file is about to be
processed a second time.

C<follow_skip==2> causes File::Find to ignore any duplicate files and
directories but to proceed normally otherwise.

=item C<dangling_symlinks>

If true and a code reference, will be called with the symbolic link
name and the directory it lives in as arguments. Otherwise, if true
and warnings are on, warning "symbolic_link_name is a dangling
symbolic link\n" will be issued. If false, the dangling symbolic link
will be silently ignored.

=item symlinks

Be aware that the option to follow symbolic links can be dangerous.
Depending on the structure of the directory tree (including symbolic
links to directories) you might traverse a given (physical) directory
more than once (only if C<follow_fast> is in effect).
Furthermore, deleting or changing files in a symbolically linked
directory
might cause very unpleasant surprises, since you delete or change files
in an unknown directory.

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top