[issue33105] os.path.isfile returns false on Windows when file path is longer than 260 characters
Eryk Sun
report at bugs.python.org
Mon Mar 19 21:12:55 EDT 2018
Eryk Sun <eryksun at gmail.com> added the comment:
> If you use os.listdir() on the networked folder, the log file
> will come up.
Querying a file's parent directory (e.g. via os.scandir in Python 3) can provide a basic stat (i.e. attributes, reparse tag, size, and timestamps) when opening the file directly fails. Currently the os.[l]stat implementation in Python 3 falls back on querying the directory for ERROR_ACCESS_DENIED (e.g. due to a file's security, delete disposition, or an exclusive open) and ERROR_SHARING_VIOLATION (e.g. a system paging file).
This could be expanded to ERROR_PATH_NOT_FOUND, which among other reasons, can indicate the path was too long if long-path support isn't available. This would expand the reach to all files in which the path of the parent directory is less than MAX_PATH. This would keep os.[l]stat consistent with os.listdir and os.scandir, which it currently is not. For example:
>>> parent_path, filename = os.path.split(path)
>>> len(path), len(parent_path), filename
(264, 255, 'spam.txt')
>>> os.path.exists(path)
False
>>> entry = next(os.scandir(parent_path))
>>> entry.name
'spam.txt'
>>> entry.stat()
os.stat_result(st_mode=33206, st_ino=0, st_dev=0, st_nlink=0,
st_uid=0, st_gid=0, st_size=0, st_atime=1521507879,
st_mtime=1521507879, st_ctime=1521507879)
----------
components: +Windows
stage: -> needs patch
versions: +Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33105>
_______________________________________
More information about the Python-bugs-list
mailing list