Following symbolic links (symlink/readlink) seems to me to be a hard problem. As in, if you don't watch out for all the minutae, you can get hammered.

So, I'm hoping someone already has solved that problem in a way accessible in perl.

I'm not looking to follow a symlink all the way to its end - the filesystem does a superb job of that already. I'm actually looking, in my case, for a particular actual symlink. I want to evaluate each symlink in the chain to determine whether I want to archive the target file, or the symlink itself. The criteria is simple, and thus less interesting (if a symlink matches a particular regular expression, I want to go to the next one in the chain, which could be the target file, otherwise I want to keep the symlink as is). However, trying to determine the symlink chain is difficult.

For example, using a simple chain of "S" (for "Symlink"), we could have:

foo -> S/foo S/foo -> S/foo # that's not a circular loop - there's an S in S S/S/foo -> ../lib/foo # keep the symlink because it doesn't start with + "S/"

Note that the filesystem I'm looking at is NFS-mounted, and read-only. And the directory structure I'm looking at is multiple-GB in size, so copying the whole thing becomes somewhat prohibitive in time (not so much in space). Especially following the symlinks during such a copy - we start jumping around from NFS server to NFS server.

Has anyone had to deal with this type of thing before? Are there modules out there that I missed which would help me go through this? Or is there a simplification that I'm just not seeing?

Thanks,


In reply to Following symlinks manually by Tanktalus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.