[Baypiggies] Unlinking symlinks

Christopher Lee-Messer chris.leemesser at gmail.com
Sat May 1 02:45:24 CEST 2010


Perhaps this would be useful if you absolutely want to do a restore.

import os

def safe_unlink(filepath):
    """
    remove symlink given by string filepath
    check that is really a symbolic link not a regular file or directory
    """
    if os.path.islink(filepath):
        os.remove(filepath)
        return True
    else:
        return False


On Fri, Apr 30, 2010 at 5:02 PM, Keith Dart <keith at dartworks.biz> wrote:
>
> === On Fri, 04/30, Glen Jarvis wrote: ===
> > As everyone can see why I wanted to get an *absolute exact* answer on
> > this... This is *not* a mistake I can make :(  Just doing a tests
> > aren't sufficient for this situation :( It's like doing proof in our
> > math class... We need it to be true for all cases, and not just a
> > single case...
> ===
>
> That is very interesting. I wouldn't have expected that. FYI, the Apple
> man page is here:
>
> http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man7/symlink.7.html#//apple_ref/doc/man/7/symlink
>
> It doesn't say anything about that trailing slash behavior.
>
> This is a good example of why you always need to test things out. :-)
> Also, it's a good idea to develop and test on the same platform that
> you deploy on.
>
>
> -- 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



--
Christopher Lee-Messer MD PhD
Instructor in Pediatric Neurology
Postdoctoral Fellow - Deisseroth Lab
Stanford Medical Center
chris (at) lee-messer.net


More information about the Baypiggies mailing list