changeset: 99217:05d6ddf2b7c2 branch: 3.4 parent: 99214:9b3144716d17 user: Martin Panter date: Thu Nov 19 04:48:44 2015 +0000 files: Lib/os.py Lib/test/test_os.py Misc/NEWS description: Issue #25583: Avoid incorrect errors raised by os.makedirs(exist_ok=True) diff -r 9b3144716d17 -r 05d6ddf2b7c2 Lib/os.py --- a/Lib/os.py Thu Nov 19 13:28:47 2015 -0800 +++ b/Lib/os.py Thu Nov 19 04:48:44 2015 +0000 @@ -226,7 +226,7 @@ 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): @@ -235,8 +235,10 @@ 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 -r 9b3144716d17 -r 05d6ddf2b7c2 Lib/test/test_os.py --- a/Lib/test/test_os.py Thu Nov 19 13:28:47 2015 -0800 +++ b/Lib/test/test_os.py Thu Nov 19 04:48:44 2015 +0000 @@ -971,6 +971,9 @@ 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) + @unittest.skipUnless(hasattr(os, 'chown'), 'test needs os.chown') def test_chown_uid_gid_arguments_must_be_index(self): stat = os.stat(support.TESTFN) diff -r 9b3144716d17 -r 05d6ddf2b7c2 Misc/NEWS --- a/Misc/NEWS Thu Nov 19 13:28:47 2015 -0800 +++ b/Misc/NEWS Thu Nov 19 04:48:44 2015 +0000 @@ -106,6 +106,9 @@ Library ------- +- Issue #25583: Avoid incorrect errors raised by os.makedirs(exist_ok=True) + when the OS gives priority to errors such as EACCES over EEXIST. + - Issue #25593: Change semantics of EventLoop.stop() in asyncio. - Issue #6973: When we know a subprocess.Popen process has died, do