|
57 | 57 | if hasattr(_os, 'O_BINARY'): |
58 | 58 | _bin_openflags |= _os.O_BINARY |
59 | 59 |
|
60 | | -TMP_MAX = 100 |
| 60 | +if hasattr(_os, 'TMP_MAX'): |
| 61 | + TMP_MAX = _os.TMP_MAX |
| 62 | +else: |
| 63 | + TMP_MAX = 10000 |
61 | 64 |
|
62 | 65 | # This variable _was_ unused for legacy reasons, see issue 10354. |
63 | 66 | # But as of 3.5 we actually use it at runtime so changing it would |
@@ -210,14 +213,10 @@ def _get_default_tempdir(dirlist=None): |
210 | 213 | except FileExistsError: |
211 | 214 | pass |
212 | 215 | except PermissionError: |
213 | | - # On Posix, this exception is raised when the user has no |
214 | | - # write access to the parent directory. |
215 | | - # On Windows, it is also raised when a directory with |
216 | | - # the chosen name already exists, or if the parent directory |
217 | | - # is not a directory. |
218 | | - # We cannot distinguish between "directory-exists-error" and |
219 | | - # "access-denied-error". |
220 | | - if _os.name == 'nt' and _os.path.isdir(dir): |
| 216 | + # This exception is thrown when a directory with the chosen name |
| 217 | + # already exists on windows. |
| 218 | + if (_os.name == 'nt' and _os.path.isdir(dir) and |
| 219 | + _os.access(dir, _os.W_OK)): |
221 | 220 | continue |
222 | 221 | break # no point trying more names in this directory |
223 | 222 | except OSError: |
@@ -259,14 +258,10 @@ def _mkstemp_inner(dir, pre, suf, flags, output_type): |
259 | 258 | except FileExistsError: |
260 | 259 | continue # try again |
261 | 260 | except PermissionError: |
262 | | - # On Posix, this exception is raised when the user has no |
263 | | - # write access to the parent directory. |
264 | | - # On Windows, it is also raised when a directory with |
265 | | - # the chosen name already exists, or if the parent directory |
266 | | - # is not a directory. |
267 | | - # We cannot distinguish between "directory-exists-error" and |
268 | | - # "access-denied-error". |
269 | | - if _os.name == 'nt' and _os.path.isdir(dir) and seq < TMP_MAX - 1: |
| 261 | + # This exception is thrown when a directory with the chosen name |
| 262 | + # already exists on windows. |
| 263 | + if (_os.name == 'nt' and _os.path.isdir(dir) and |
| 264 | + _os.access(dir, _os.W_OK)): |
270 | 265 | continue |
271 | 266 | else: |
272 | 267 | raise |
@@ -391,14 +386,10 @@ def mkdtemp(suffix=None, prefix=None, dir=None): |
391 | 386 | except FileExistsError: |
392 | 387 | continue # try again |
393 | 388 | except PermissionError: |
394 | | - # On Posix, this exception is raised when the user has no |
395 | | - # write access to the parent directory. |
396 | | - # On Windows, it is also raised when a directory with |
397 | | - # the chosen name already exists, or if the parent directory |
398 | | - # is not a directory. |
399 | | - # We cannot distinguish between "directory-exists-error" and |
400 | | - # "access-denied-error". |
401 | | - if _os.name == 'nt' and _os.path.isdir(dir) and seq < TMP_MAX - 1: |
| 389 | + # This exception is thrown when a directory with the chosen name |
| 390 | + # already exists on windows. |
| 391 | + if (_os.name == 'nt' and _os.path.isdir(dir) and |
| 392 | + _os.access(dir, _os.W_OK)): |
402 | 393 | continue |
403 | 394 | else: |
404 | 395 | raise |
|
0 commit comments