[plt-scheme] Determine that two paths point to same file?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue May 26 16:54:19 EDT 2009

At Tue, 26 May 2009 19:45:24 +0100, Erich Rast wrote:
> Is there a PLT scheme-native way to reliably determine whether two  
> paths point to the same file or folder? 

If you have two ports for open files, you can use `port-file-identity'
to compare them, and that's actually reliable.

Otherwise, as far as I know, there isn't actually a way to do that at
the OS level. Normalizing paths is usually a good approximation...

> Which path "normalization"  
> function should I use?

I recommend `simplify-path' combined with `normal-case-path'.

Beware, though, that `normal-case-path' doesn't case-fold paths under
Mac OS X; that's because case-normalization is actually a property of
the filesystem, and not the OS. It's apparently possible to determine
whether a filesystem is case-sensitive via getattrlist(), but
`normal-case-path' currently doesn't try to use that information.

Plenty of other things could go wrong, though they usually don't. For
example, a filesystem could be mounted on multiple paths, so that files
can be accessed through different paths, a file could be hard-linked to
multiple paths, soft links could change in between two queries, or a
perverse OS could treat every path ending with "COM1" (plus any
extension) as a particular device.

Posted on the users mailing list.