This patch reverts changes made to `os.makedirs()` in Python 3.7. Prior to Python 3.7, mode argument also affected newly-created intermediate-level directories, and that is not the case anymore [1]. The reason was that with mode preventing directory creating, the function fails after it creates the first intermediate-level directory. Since there is Solaris code that depends on the old behavior, this patch brings it back. Note that we are not the only ones affected by this; upstream is already considering reverting this change [2]. For reference: [1] https://bugs.python.org/issue19930 [2] https://bugs.python.org/issue42367 diff -wpruN --no-dereference '--exclude=*.orig' a~/Lib/os.py a/Lib/os.py --- a~/Lib/os.py 1970-01-01 00:00:00 +++ a/Lib/os.py 1970-01-01 00:00:00 @@ -215,7 +215,7 @@ def makedirs(name, mode=0o777, exist_ok= head, tail = path.split(head) if head and tail and not path.exists(head): try: - makedirs(head, exist_ok=exist_ok) + makedirs(head, mode, exist_ok) except FileExistsError: # Defeats race condition when another thread created the path pass diff -wpruN --no-dereference '--exclude=*.orig' a~/Lib/test/test_os.py a/Lib/test/test_os.py --- a~/Lib/test/test_os.py 1970-01-01 00:00:00 +++ a/Lib/test/test_os.py 1970-01-01 00:00:00 @@ -1764,12 +1764,12 @@ class MakedirTests(unittest.TestCase): base = os_helper.TESTFN parent = os.path.join(base, 'dir1') path = os.path.join(parent, 'dir2') - os.makedirs(path, 0o555) + os.makedirs(path, 0o755) self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.isdir(path)) if os.name != 'nt': - self.assertEqual(os.stat(path).st_mode & 0o777, 0o555) - self.assertEqual(os.stat(parent).st_mode & 0o777, 0o775) + self.assertEqual(os.stat(path).st_mode & 0o777, 0o755) + self.assertEqual(os.stat(parent).st_mode & 0o777, 0o755) @unittest.skipIf( support.is_emscripten or support.is_wasi,