It's a good solution, but I can think of two limitations.
-
That will work for symbolic links (on most devices), but not for hard links (other than "." and "..").
$ echo foo > a
$ ln a b
$ cat b
foo
$ perl -MCwd=abs_path -E'say abs_path($_) for @ARGV' a b
/tmp/a
/tmp/b
You might be able to check stat's device plus inode fields to address this limitation on some devices on some systems.
-
It also won't necessarily work across devices (since you could access the same file via two devices). The following all refer to the same file:
C:\Temp\file
\\?\C:\Temp\file # Via UNC path
\\localhost\C$\Temp\file # Via localhost
\\tribble\C$\Temp\file # Via domain name
\\10.0.0.6\C$\Temp\file # Via IP address
\\localhost\share\file # Via share
Z:\file # Given subst Z: C:\Temp
In general, this isn't solvable.