in reply to Re: Following symlinks manually
in thread Following symlinks manually

Yes, much harder ;-)

Try this at the shell:

mkdir a mkdir b ln -s a S ln -s ../b S/S touch b/foo ln -s S/foo foo ln -s S/foo S/foo
Now, take a look around for a bit. And then try your chase_links on foo.
perl -e 'my $file = shift; while(defined(my $link = readlink $file)) { + print "LINK: $file\n"; $file = $link; sleep 1; } print "NOT LINK: $f +ile\n"' foo
Note the sleep in there - I did that to make it easier to kill, 'cuz it's going to go on forever.

One needs to keep careful track of current directories to figure out where the relative links are actually relative to.

Replies are listed 'Best First'.
Re^3: Following symlinks manually
by davidrw (Prior) on Jan 15, 2007 at 23:06 UTC

      A cursory glance at File::Spec::Link says it probably will work. I'll go away now to test it. Thanks. I searched CPAN, but coming up with the right search terms is always key!

      (...)

      Yes, that looks right. I think my solution is something like this:

      use File::Spec::Link; my $curlink = shift; my $linkto; while ( ($linkto = readlink($curlink)) and $linkto =~ m:^S/: ) { print "from $curlink "; $curlink = File::Spec::Link->linked($curlink); print "to $curlink\n"; } if (-l $curlink) { # do stuff with readlink($curlink) } else { # do stuff with $curlink (now a file) }
      Thanks!