JavaFan has asked for the wisdom of the Perl Monks concerning the following question:
Works like a charm on Unix.# Return false if either files doesn't exist, or if we # cannot stat either file. sub is_same { my ($file1, $file2) = @_; return unless -f $file1 && -f $file2; return unless my ($dev1, $ino1) = (lstat $file1)[0, 1]; return unless my ($dev2, $ino2) = (lstat $file2)[0, 1]; return $dev1 == $dev2 && $ino1 == $ino2; }
I've no idea how that works under non-Unix systems.
(Note, I'm not trying to see if two paths are identical - File::Spec has methods for that. But files can have more than one name (hard links), or refer to another file (sym links) and I want to know if two, possibly different, paths point to the same file.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing if two paths point to the same file.
by ikegami (Patriarch) on Jan 30, 2009 at 13:47 UTC | |
|
Re: Testing if two paths point to the same file.
by codeacrobat (Chaplain) on Jan 30, 2009 at 14:59 UTC | |
by MidLifeXis (Monsignor) on Jan 30, 2009 at 15:19 UTC | |
by lostjimmy (Chaplain) on Jan 30, 2009 at 15:12 UTC | |
by ikegami (Patriarch) on Jan 30, 2009 at 15:29 UTC | |
|
Re: Testing if two paths point to the same file.
by repellent (Priest) on Feb 01, 2009 at 23:29 UTC | |
by parv (Parson) on Feb 02, 2009 at 23:52 UTC | |
by repellent (Priest) on Feb 03, 2009 at 15:39 UTC |