diff options
| author | Martin Panter <vadmium+py@gmail.com> | 2015-11-20 02:37:29 +0000 |
|---|---|---|
| committer | Martin Panter <vadmium+py@gmail.com> | 2015-11-20 02:37:29 +0000 |
| commit | 5e02af4961ed6278cd8e9aa4a59902fa4b16c8cb (patch) | |
| tree | 1d907d1738d50b41ce084eb44e4ef94fb87b5354 /Lib | |
| parent | 13d9b86d467539fac30370e0c87ee34683fd9721 (diff) | |
| parent | 97cabb9fa5bd257aceae724f4727fe54580c4e9f (diff) | |
| download | cpython-git-5e02af4961ed6278cd8e9aa4a59902fa4b16c8cb.tar.gz | |
Issue #25583: Merge makedirs fix from 3.5
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/os.py | 8 | ||||
| -rw-r--r-- | Lib/test/test_os.py | 3 |
2 files changed, 8 insertions, 3 deletions
@@ -230,7 +230,7 @@ def makedirs(name, mode=0o777, exist_ok=False): try: makedirs(head, mode, exist_ok) except FileExistsError: - # be happy if someone already created the path + # Defeats race condition when another thread created the path pass cdir = curdir if isinstance(tail, bytes): @@ -239,8 +239,10 @@ def makedirs(name, mode=0o777, exist_ok=False): return try: mkdir(name, mode) - except OSError as e: - if not exist_ok or e.errno != errno.EEXIST or not path.isdir(name): + except OSError: + # Cannot rely on checking for EEXIST, since the operating system + # could give priority to other errors like EACCES or EROFS + if not exist_ok or not path.isdir(name): raise def removedirs(name): diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index e8a7c97021..d6880e5770 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1039,6 +1039,9 @@ class MakedirTests(unittest.TestCase): os.makedirs(path, mode=mode, exist_ok=True) os.umask(old_mask) + # Issue #25583: A drive root could raise PermissionError on Windows + os.makedirs(os.path.abspath('/'), exist_ok=True) + def test_exist_ok_s_isgid_directory(self): path = os.path.join(support.TESTFN, 'dir1') S_ISGID = stat.S_ISGID |
