Traversing symbolic links ...

Discussion in 'Perl Misc' started by martin, Apr 21, 2006.

  1. martin

    martin Guest

    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
     
    martin, Apr 21, 2006
    #1
    1. Advertising

  2. martin wrote:
    > 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
    --
    Mahesh Asolkar
    asolkar-at-gmail-dot-com
     
    Mahesh Asolkar, Apr 21, 2006
    #2
    1. Advertising

  3. martin

    martin Guest

    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


    Mahesh Asolkar wrote:
    > martin wrote:
    > > 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
    > --
    > Mahesh Asolkar
    > asolkar-at-gmail-dot-com
     
    martin, Apr 21, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim
    Replies:
    4
    Views:
    7,045
  2. Juha Laiho
    Replies:
    0
    Views:
    688
    Juha Laiho
    Jul 20, 2004
  3. Nick Howes
    Replies:
    6
    Views:
    576
    Toby A Inkster
    Nov 24, 2003
  4. pekka.niiranen
    Replies:
    0
    Views:
    274
    pekka.niiranen
    Feb 10, 2004
  5. Ken Fine
    Replies:
    2
    Views:
    139
    Ken Fine
    Aug 14, 2003
Loading...

Share This Page