[issue33105] os.path.isfile returns false on Windows when file path is longer than 260 characters

2021-03-01 Thread Eryk Sun


Eryk Sun  added the comment:

I'm closing this as not a bug. If the process limits DOS paths to MAX_PATH, 
then checking os.path.isfile() should not be special cased to support longer 
DOS paths because calling open() on such a path will raise FileNotFoundError. 
My suggestion in msg314126 to have stat() fall back on querying the directory 
in this case is too magical, even if it does make os.stat() more consistent 
with os.listdir() and the stat result from os.scandir().

--
resolution:  -> not a bug
stage: needs patch -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33105] os.path.isfile returns false on Windows when file path is longer than 260 characters

2018-03-19 Thread Eryk Sun

Eryk Sun  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33105] os.path.isfile returns false on Windows when file path is longer than 260 characters

2018-03-19 Thread Eryk Sun

Eryk Sun  added the comment:

Python 2.7 is all but set in stone. Changes to its behavior have to correct 
serious bugs, not work around limits in an OS. You can do that yourself. For 
example, use an extended local-device path, i.e. a path that's prefixed by 
u"?\\". This path type must be unicode, fully-qualified, and use only 
backslash as the path separator. Also, the UNC device has to be used 
explicitly. Python 2 has poor support for unicode raw strings (\u and \U 
escapes aren't disabled), so you can instead use forward slashes and 
normpath(). For example: 

f1_path = 
os.path.normpath(u"//?/UNC/tst/tc/proj/MTV/cs_fft/Milo/Fries/STL/BLNA/F1") 
log_path = os.path.join(f1_path, log_filename)
assert os.path.isfile(log_path)

--
nosy: +eryksun
title: os.isfile returns false on Windows when file path is longer than 260 
characters -> os.path.isfile returns false on Windows when file path is longer 
than 260 characters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com