[Baypiggies] Unlinking symlinks
janssen at parc.com
Sat May 1 21:19:10 CEST 2010
Andrew Akira Toulouse <andrew at atoulou.se> wrote:
> I did one additional test on top of this - if you take the same directions,
> but replace os.unlink("blahlink") with os.unlink("blahlink/"), it will
> dereference the symlink and unlink 'blah' -- trailing slashes do in fact
> dereference symlinks, even if they are files. Further, if you put some text
> in 'blah' and type 'cat blahlink/' it acts identically to 'cat blah'.
Yes, this is POSIX (2008). A slash after a symlink means, replace the
path prefix, up to and including the symlink's name, with the symlink's
value, and continue interpretation of the path. So a path ending with a
symlink but without a trailing slash refers to the symlink, but adding a
trailing slash makes it refer to the symlink's value.
This would all be better if Python had some kind of Filename object,
which would remove the dependency on wild and cross-platform-varying
path name interpretation. Of course, the "os" module is supposed to let
the underlying platform differences "show through", so...
Maybe there should be something like a "portable" module, which
recapitulates functions from the various other stdlib modules that let
the differences show through, but strictly defines the operation of
those functions. Whoa, that's Java-think!
More information about the Baypiggies