[New-bugs-announce] [issue18314] Have os.unlink remove junction points

Kim Gräsman report at bugs.python.org
Thu Jun 27 14:15:21 CEST 2013


New submission from Kim Gräsman:

os.unlink currently raises a WindowsError (Access Denied) if I attempt to unlink an NTFS junction point.

It looks trivial to allow Py_DeleteFileW [1] to remove junction points as well as proper symbolic links, as far as I can tell.

For example, the ntfslink-python library [2] only checks if both FILE_ATTRIBUTE_DIRECTORY and FILE_ATTRIBUTE_REPARSE_POINT are set.

RemoveDirectoryW is documented to handle junction points transparently, so it should just be a matter of passing the path on if it's a junction point or a symbolic link.

My motivation for this is that I have used external tools to create junction points, and am now switching to symbolic links. When deleting a directory, I need to do:

    try:
        os.unlink(link_path)
    except WindowsError as detail:
        # BACKWARD COMPATIBILITY HACK
        if detail.winerror == 5:
            _delete_junction_point(link_path)
        else:
            raise

which is a little funky. It seems like os.unlink semantics work just as well for junction points, even if they can't be created with os.symlink.

Love it/hate it?

[1] http://hg.python.org/cpython/file/44f455e6163d/Modules/posixmodule.c#l4105
[2] https://github.com/Juntalis/ntfslink-python/blob/2f6ff903f9b22942de8aa93a32a3d817124f359e/ntfslink/internals/__init__.py#L32

----------
components: Windows
messages: 191945
nosy: Kim.Gräsman
priority: normal
severity: normal
status: open
title: Have os.unlink remove junction points
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18314>
_______________________________________


More information about the New-bugs-announce mailing list