[Baypiggies] Unlinking symlinks
Andrew Akira Toulouse
andrew at atoulou.se
Fri Apr 30 22:34:54 CEST 2010
I'm pretty sure os.unlink() calls the OS's unlink function (as the name
might imply). The documentation for it (`info unlink`; the man page is a
summary which points to this) has the following:
unlink() deletes a name from the file system. If that name was
last link to a file and no processes have the file open the file
deleted and the space it was using is made available for reuse.
If the name was the last link to a file but any processes still
the file open the file will remain in existence until the last
descriptor referring to it is closed.
If the name referred to a symbolic link the link is removed.
One think you should be careful of, though, is that you do not have a slash
after the symlink. If it links to a directory then the slash dereferences
On Fri, Apr 30, 2010 at 12:35 PM, Glen Jarvis <glen at glenjarvis.com> wrote:
> I hate to ask such an absolutely simple question, but for what I'm doing I
> have to be *absolutely certain* to get this right :)
> When deleting symlinks, I think I've always used os.unlink() although it's
> the same as os.remove().
> I can't tell in the documentation, but I want to be abso-bloody-lutely
> certain that I'm deleting the link and not the file that it points to. This
> is for a very large file system clean-up on a data system that would be a
> bear to replace. We wish to clean up specific symbolic links that I can find
> easily, but not the files that they point to.
> Is os.unlink() guaranteed to touch the symlink only? Also, semantically,
> is this "unlinking" a hard unlinking and therefore the same as remove (i.e.,
> which would be easier for someone who is reading the code to understand/yet
> still be accurate).
> Whatever you can do or imagine, begin it;
> boldness has beauty, magic, and power in it.
> -- Goethe
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Baypiggies