This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, kwarzecha7, paul.moore, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Date 2016-05-05.21:37:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1462484266.84.0.768558176371.issue26968@psf.upfronthosting.co.za>
In-reply-to
Content
The access control list of a file may not grant or may deny the current user the right to read file attributes (i.e. lstat). Generally you don't have to worry about granted access to parent directories when attempting to stat the file or directory, since even standard users have SeChangeNotifyPrivilege to bypass path traversal access checks. In this case, ISTM that we at least know the file exists if lstat raises PermissionError instead of FileNotFoundError. Currently os.path.lexists returns False for any OSError, without distinguishing between these two cases.

You may also come across a similar issue when a file's delete disposition is set, since Windows doesn't allow opening a deleted file, even to read its attributes, and it doesn't actually unlink the file or directory until all references are closed. 

For example, create a directory, opened with delete sharing:

    >>> h = _winapi.CreateFile('testglob', 0x40000000, 7, 0, 1,
    ...                        0x2000000|0x1000000|0x80|0x10, 0)
    >>> os.path.isdir('testglob')
    True

Before removing the directory, it can be globbed directly:

    >>> glob.glob('testglob')
    ['testglob']

After removing the directory, it can only be globbed indirectly by listing its parent directory:

    >>> os.rmdir('testglob')
    >>> os.lstat('testglob')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    PermissionError: [WinError 5] Access is denied: 'testglob'

    >>> glob.glob('testglob')
    []
    >>> glob.glob('testglob*')
    ['testglob']

Once the handle is closed, the directory is unlinked:

    >>> _winapi.CloseHandle(h)
    >>> os.lstat('testglob')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    FileNotFoundError: [WinError 2] The system cannot find the file specified: 'testglob'
    >>> glob.glob('testglob*')
    []
History
Date User Action Args
2016-05-05 21:37:46eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, serhiy.storchaka, steve.dower, kwarzecha7
2016-05-05 21:37:46eryksunsetmessageid: <1462484266.84.0.768558176371.issue26968@psf.upfronthosting.co.za>
2016-05-05 21:37:46eryksunlinkissue26968 messages
2016-05-05 21:37:46eryksuncreate