in reply to Following symlinks manually
It seems pretty straight forward to me, so maybe I'm missing something. readlink returns undef when you point it at a non-link, so...
sub chase_links { my ( $file ) = @_; while ( defined ( my $link = readlink $file ) ) { print "LINK: $file"; $file = $link; } print "NOT LINK: $file"; }
That will list out the links until it gets to a real file. You can insert any logic you like into that loop to short circuit or what-have-you. Is this problem harder than I think?
UPDATE: Oh, I guess it is harder than I thought. The above only works if all links are absolute or relative to the current directory. To work with scattered relative links, you'd have to chdir or track the base directories.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Following symlinks manually
by Tanktalus (Canon) on Jan 15, 2007 at 22:47 UTC | |
by davidrw (Prior) on Jan 15, 2007 at 23:06 UTC | |
by Tanktalus (Canon) on Jan 16, 2007 at 00:20 UTC |