[issue46654] file_open doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

Eryk Sun report at bugs.python.org
Sat Feb 5 18:20:21 EST 2022


Eryk Sun <eryksun at gmail.com> added the comment:

Builtin open() calls C open(). This C function supports whatever path types are supported natively. In Windows, C open() calls WinAPI CreateFileW(), which does not support "file://" URIs. The Windows API handles it as a relative path, which gets resolved against the current working directory. For example:

    >>> os.getcwd()
    'C:\\Temp'
    >>> nt._getfullpathname('file:////host/share/file')
    'C:\\Temp\\file:\\host\\share\\file'
    >>> nt._getfullpathname('file://host/share/file')
    'C:\\Temp\\file:\\host\\share\\file'

As to the resolved path somehow working, that generally will not be the case. Most filesystems in Windows will reject a path component named "file:" as an invalid name. The ":" character is usually disallowed in base file and directory names, since some Windows filesystems use it as a delimiter in file streams, e.g. "name:stream_name:stream_type". The default data stream in a regular file has no stream name, and its stream type is "$DATA". Thus for base name "file", the default data stream can be referenced explicitly as "file::$DATA". But just "file:", with neither a stream name nor a stream type, is an invalid name.

----------
nosy: +eryksun

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46654>
_______________________________________


More information about the Python-bugs-list mailing list