bpo-19930: The mode argument of os.makedirs() no longer affects the file (#799)
permission bits of newly-created intermediate-level directories.
This commit is contained in:
parent
5619ab2db3
commit
e304e33c16
|
@ -1741,8 +1741,11 @@ features:
|
||||||
Recursive directory creation function. Like :func:`mkdir`, but makes all
|
Recursive directory creation function. Like :func:`mkdir`, but makes all
|
||||||
intermediate-level directories needed to contain the leaf directory.
|
intermediate-level directories needed to contain the leaf directory.
|
||||||
|
|
||||||
The *mode* parameter is passed to :func:`mkdir`; see :ref:`the mkdir()
|
The *mode* parameter is passed to :func:`mkdir` for creating the leaf
|
||||||
description <mkdir_modebits>` for how it is interpreted.
|
directory; see :ref:`the mkdir() description <mkdir_modebits>` for how it
|
||||||
|
is interpreted. To set the file permission bits of any newly-created parent
|
||||||
|
directories you can set the umask before invoking :func:`makedirs`. The
|
||||||
|
file permission bits of existing parent directories are not changed.
|
||||||
|
|
||||||
If *exist_ok* is ``False`` (the default), an :exc:`OSError` is raised if the
|
If *exist_ok* is ``False`` (the default), an :exc:`OSError` is raised if the
|
||||||
target directory already exists.
|
target directory already exists.
|
||||||
|
@ -1767,6 +1770,10 @@ features:
|
||||||
.. versionchanged:: 3.6
|
.. versionchanged:: 3.6
|
||||||
Accepts a :term:`path-like object`.
|
Accepts a :term:`path-like object`.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.7
|
||||||
|
The *mode* argument no longer affects the file permission bits of
|
||||||
|
newly-created intermediate-level directories.
|
||||||
|
|
||||||
|
|
||||||
.. function:: mkfifo(path, mode=0o666, *, dir_fd=None)
|
.. function:: mkfifo(path, mode=0o666, *, dir_fd=None)
|
||||||
|
|
||||||
|
|
|
@ -247,6 +247,13 @@ Changes in the Python API
|
||||||
and module are affected by this change.
|
and module are affected by this change.
|
||||||
(Contributed by INADA Naoki and Eugene Toder in :issue:`29463`.)
|
(Contributed by INADA Naoki and Eugene Toder in :issue:`29463`.)
|
||||||
|
|
||||||
|
* The *mode* argument of :func:`os.makedirs` no longer affects the file
|
||||||
|
permission bits of newly-created intermediate-level directories.
|
||||||
|
To set their file permission bits you can set the umask before invoking
|
||||||
|
``makedirs()``.
|
||||||
|
(Contributed by Serhiy Storchaka in :issue:`19930`.)
|
||||||
|
|
||||||
|
|
||||||
CPython bytecode changes
|
CPython bytecode changes
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ def makedirs(name, mode=0o777, exist_ok=False):
|
||||||
head, tail = path.split(head)
|
head, tail = path.split(head)
|
||||||
if head and tail and not path.exists(head):
|
if head and tail and not path.exists(head):
|
||||||
try:
|
try:
|
||||||
makedirs(head, mode, exist_ok)
|
makedirs(head, exist_ok=exist_ok)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
# Defeats race condition when another thread created the path
|
# Defeats race condition when another thread created the path
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1118,6 +1118,18 @@ class MakedirTests(unittest.TestCase):
|
||||||
'dir5', 'dir6')
|
'dir5', 'dir6')
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
|
|
||||||
|
def test_mode(self):
|
||||||
|
with support.temp_umask(0o002):
|
||||||
|
base = support.TESTFN
|
||||||
|
parent = os.path.join(base, 'dir1')
|
||||||
|
path = os.path.join(parent, 'dir2')
|
||||||
|
os.makedirs(path, 0o555)
|
||||||
|
self.assertTrue(os.path.exists(path))
|
||||||
|
self.assertTrue(os.path.isdir(path))
|
||||||
|
if os.name != 'nt':
|
||||||
|
self.assertEqual(stat.S_IMODE(os.stat(path).st_mode), 0o555)
|
||||||
|
self.assertEqual(stat.S_IMODE(os.stat(parent).st_mode), 0o775)
|
||||||
|
|
||||||
def test_exist_ok_existing_directory(self):
|
def test_exist_ok_existing_directory(self):
|
||||||
path = os.path.join(support.TESTFN, 'dir1')
|
path = os.path.join(support.TESTFN, 'dir1')
|
||||||
mode = 0o777
|
mode = 0o777
|
||||||
|
|
|
@ -287,6 +287,9 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- bpo-19930: The mode argument of os.makedirs() no longer affects the file
|
||||||
|
permission bits of newly-created intermediate-level directories.
|
||||||
|
|
||||||
- bpo-29884: faulthandler: Restore the old sigaltstack during teardown.
|
- bpo-29884: faulthandler: Restore the old sigaltstack during teardown.
|
||||||
Patch by Christophe Zeitouny.
|
Patch by Christophe Zeitouny.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue