-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Failure to try another name for tempfile when directory with chosen name exists on windows #63049
Comments
When directory exists with a name chosen for new temporary file, OSError with EACCESS errno is thrown on windows, while attempts to chose another name only happen on EEXIST errors. To reproduce, run import sys
import tempfile
import os print sys.platform # Mock random names to ensure collision.
tempfile._RandomNameSequence = lambda: iter(['a', 'a', 'b'])
d = tempfile.mkdtemp()
print d try: Expected result: Actual result:
win32
2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]
c:\users\shcher~1\appdata\local\temp\tmpa
Traceback (most recent call last):
File "hz.py", line 13, in <module>
print tempfile.NamedTemporaryFile().name
File "C:\python_27_amd64\files\lib\tempfile.py", line 454, in NamedTemporaryFile
(fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
File "C:\python_27_amd64\files\lib\tempfile.py", line 235, in _mkstemp_inner
fd = _os.open(file, flags, 0600)
OSError: [Errno 13] Permission denied: 'c:\\users\\shcher~1\\appdata\\local\\temp\\tmpa' |
The fix looks good to me, in general. Could you create a test that goes along? My only (minor) doubt is whether this should be generalized, in two dimensions:
For (2) I don't think doing anything is necessary at this point - the added test may help because it can fail for some strange platform at some point and then the solution should be obvious. As for (1), adding EPERM into the condition probably can't hurt and it will make Python 2.7 behave more consistently with 3.x in case of some undocumented Windows behavior. |
|
Re (1) let's leave it as it is, now. I don't think it really matters. I left some comments in Rietveld. |
New changeset 7611e7244bdd by Eli Bendersky in branch '3.3': New changeset 035b61b52caa by Eli Bendersky in branch 'default': |
New changeset e0037f266d45 by Eli Bendersky in branch '2.7': |
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: