[Baypiggies] Unlinking symlinks

Andrew Akira Toulouse andrew at atoulou.se
Sat May 1 00:07:12 CEST 2010


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'.

--Andy

On Fri, Apr 30, 2010 at 2:50 PM, Brent Tubbs <brent.tubbs at gmail.com> wrote:

> 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
>>
>
>
> _______________________________________________
> 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/40184c90/attachment.html>


More information about the Baypiggies mailing list