[Baypiggies] Unlinking symlinks

Brent Tubbs brent.tubbs at gmail.com
Fri Apr 30 23:50:26 CEST 2010


I did a quick test creating and symlinking a file in bash, then calling
unlink in Python, and finally looking at the results again from bash.  The
source file appears to remain untouched.  Complete bash and python steps:

brent at mae ~/tmp $ touch blah
brent at mae ~/tmp $ ls -l
total 0
-rw-r--r-- 1 brent brent 0 2010-04-30 14:46 blah
brent at mae ~/tmp $ ln -s blah blahlink
brent at mae ~/tmp $ ls -l
total 0
-rw-r--r-- 1 brent brent 0 2010-04-30 14:46 blah
lrwxrwxrwx 1 brent brent 4 2010-04-30 14:46 blahlink -> blah
brent at mae ~/tmp $ ipython

In [1]: import os

In [2]: os.unlink('blahlink')

In [3]:
Do you really want to exit ([y]/n)?
brent at mae ~/tmp $ ls -l
total 0
-rw-r--r-- 1 brent brent 0 2010-04-30 14:46 blah

Hope that helps!
Brent

On Fri, Apr 30, 2010 at 1:52 PM, Keith Dart <keith at dartworks.biz> wrote:

> === On Fri, 04/30, Glen Jarvis wrote: ===
> > 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).
>
> ===
>
> That is just wrapper for the unlink stdlib function.
>
> man 2 unlink says:
>
>  If the name referred to a symbolic link the link is removed.
>
> You can also do a little test to verify it.
>
>
>
> -- Keith Dart
>
> --
> -- --------------------
> Keith Dart
> <keith at dartworks.biz>
> =======================
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100430/088f8020/attachment-0001.html>


More information about the Baypiggies mailing list