-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os.path.exists(os.devnull) regression on windows #45652
Comments
When moving from Python 2.4 to Python 2.5, my program stopped working on The os.devnul variable contains the name of the "null file", which is Opening the "nul" file with open("nul", "r") works fine, but |
It's called os.devnull, and nothing else. |
You migrated only of Python version, or also of windows installation? I checked Py25 and Py23 in my Win 2k, and in both I have the same behaviour: C:\Python23>python
Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.stat("nul")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OSError: [Errno 22] Invalid argument: 'nul'
>>> os.path.exists("nul")
False
>>> I checked the os.stat() function because the documentation says that if BTW, note that if you call to the GetFileAttributesEx() function of Because of this, I'd say that current behaviour of os.exists() is ok, Thanks! |
I tried it on two different machines, and got two different answers: conan$ /cygdrive/c/Python25/python -c 'import os.path; print conan$ /cygdrive/c/Python24/python -c 'import os; print os.stat("nul")'
Traceback (most recent call last):
File "<string>", line 1, in ?
OSError: [Errno 22] Invalid argument: 'nul'
conan$ /cygdrive/c/Python25/python -c 'import os; print os.stat("nul")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
WindowsError: [Error 87] The parameter is incorrect: 'nul' titti$ /cygdrive/c/Python24/python -c 'import os.path; print titti$ /cygdrive/c/Python24/python -c 'import os; print os.stat("nul")'
(33206, 0L, 3, 1, 0, 0, 0L, -1, -1, -1)
titti$ /cygdrive/c/Python25/python -c 'import os; print
os.stat("nul")'Traceback (most recent call last):
File "<string>", line 1, in <module>
WindowsError: [Error 87] The parameter is incorrect: 'nul' I ran it from a cygwin prompt, but the pythons are native. So you are correct that it doesn't work as I expected in Python 2.4 I don't know what the differences between these installation are. |
I tried this under Python 2.3.3, 2.5.1 (native) and 2.3.4 (cygwin). The C:\Python23>python
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> print os.path.exists('nul')
True
C:\Python25>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> print os.path.exists('nul')
False
$ python
Python 2.3.4 (#1, Jun 13 2004, 11:21:03)
[GCC 3.3.1 (cygming special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> print os.path.exists('nul')
True So there does seem to be a change in behaviour at 2.5. |
Ok, it seems that Python 2.5 implements two new functions In both functions we find: static BOOL WINAPI
Py_GetFileAttributesExA(LPCSTR pszFile,
GET_FILEEX_INFO_LEVELS level,
LPVOID pv)
{
BOOL result;
LPWIN32_FILE_ATTRIBUTE_DATA pfad = pv;
/* First try to use the system's implementation, if that is
available and either succeeds to gives an error other than
that it isn't implemented. */
check_gfax();
if (gfaxa) {
result = gfaxa(pszFile, level, pv);
if (result || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
return result;
}
/* It's either not present, or not implemented.
Emulate using FindFirstFile. */
if (level != GetFileExInfoStandard) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
...
static BOOL WINAPI
Py_GetFileAttributesExW(LPCWSTR pszFile,
GET_FILEEX_INFO_LEVELS level,
LPVOID pv)
{
BOOL result;
LPWIN32_FILE_ATTRIBUTE_DATA pfad = pv;
/* First try to use the system's implementation, if that is
available and either succeeds to gives an error other than
that it isn't implemented. */
check_gfax();
if (gfaxa) {
result = gfaxw(pszFile, level, pv);
if (result || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
return result;
}
/* It's either not present, or not implemented.
Emulate using FindFirstFile. */
if (level != GetFileExInfoStandard) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
... I'm neither a C nor a win32api programmer - can anyone explain the |
The purpose of Py_GetFileAttributesEx* is to wrap GetFileAttributesEx, |
As Facundo found out, the behavior of os.path.exists is fairly |
Please disregard Cygwin Python for this discussion. It (probably) uses |
>>> import os.path
>>> os.path.exists("con")
False
>>> os.path.exists("nul")
False
>>> os.path.exists("prn")
False This is in Windows 2000 (5.00.2195) sp4, using *both* Python 2.3.5 and Personally, I'm +1 with Mark Hammond about this:
Taking in consideration that *now* it behaves equally in different I'll wait some days to get more behaviour responses, though. Regards, |
All these tests on Windows XP SP4, executing os.stat("nul") Python 2.1 thru 2.4 raises: Python 2.5 gives a different error: |
Well, I was trying not to resurrect this old issue, but looks like I did it accidentally. Hi there, old hands! We miss you :) We also figured out a new [l]stat() implementation on Windows that handles symlinks and junctions better, and also non-file types such as NUL. So I guess I'll mark this as resolved in Python 3.8 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: