Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
From File::Find:
* dangling_symlinks
Specifies what to do with symbolic links whose target doesn't exist. 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, a warning of the form "symbolic_link_name is a dangling symbolic link\n"
will be issued. If false, the dangling symbolic link will be silently ignored.

And stat/lstat (WP):

The stat() and lstat() functions take a filename argument. If the file is a symbolic link,
stat() returns attributes of the eventual target of the link, while lstat() returns attributes
of the link itself. The fstat() function takes a file descriptor argument instead, and returns
attributes of the file that it identifies.
Note: Perl docs - stat, lstat

It seems that the question that needs to be answered is, is dangling_symlinks invoked for conditions equivalent to -l && !-e on the file is true?

From what I dug up while getting the above clarifications, it seems that there are great pains in both documents (and elsewhere) that differentiate the link itself and the file that is the target of the link. So make sure you're being consistent in what you're testing and that you are recreating the identical conditions for which dangling_symlinks is invoked.

Another thought occurred to me that there could be some interactions in

sub{if (-l && !-e){

Since you're testing $_ (I assume) when you might want (or not) to do something like sub{if (-l && !-e _){, which is going to avoid calling stat or lstat again. Not super solid on this nuance, but just saying to verify it's doing what you expect.

Update (from From -X):

If any of the file tests (or either the stat or lstat operator) is given the special filehandle consisting of
a solitary underline, then the stat structure of the previous file test (or stat operator) is used, saving a
system call. (This doesn't work with -t , and you need to remember that lstat and -l leave values in the stat
structure for the symbolic link, not the real file.) (Also, if the stat buffer was filled by an lstat call,
-T and -B will reset it with the results of stat _ ).

So there you go...hopefully clear as mud now. :)


In reply to Re^2: File::Find and remove invalid symlinks question by perlfan
in thread File::Find and remove invalid symlinks question by redtux

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found