mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #19921: When Path.mkdir() is called with parents=True, any missing parent is created with the default permissions, ignoring the mode argument (mimicking the POSIX "mkdir -p" command).
Patch by Serhiy.
This commit is contained in:
parent
c274fd22ed
commit
0048c98fef
4 changed files with 20 additions and 4 deletions
|
@ -768,7 +768,10 @@ call fails (for example because the path doesn't exist):
|
||||||
and access flags. If the path already exists, :exc:`OSError` is raised.
|
and access flags. If the path already exists, :exc:`OSError` is raised.
|
||||||
|
|
||||||
If *parents* is true, any missing parents of this path are created
|
If *parents* is true, any missing parents of this path are created
|
||||||
as needed. If *parents* is false (the default), a missing parent raises
|
as needed; they are created with the default permissions without taking
|
||||||
|
*mode* into account (mimicking the POSIX ``mkdir -p`` command).
|
||||||
|
|
||||||
|
If *parents* is false (the default), a missing parent raises
|
||||||
:exc:`OSError`.
|
:exc:`OSError`.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1101,7 +1101,7 @@ class Path(PurePath):
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != ENOENT:
|
if e.errno != ENOENT:
|
||||||
raise
|
raise
|
||||||
self.parent.mkdir(mode, True)
|
self.parent.mkdir(parents=True)
|
||||||
self._accessor.mkdir(self, mode)
|
self._accessor.mkdir(self, mode)
|
||||||
|
|
||||||
def chmod(self, mode):
|
def chmod(self, mode):
|
||||||
|
|
|
@ -1478,7 +1478,6 @@ class _BasePathTest(object):
|
||||||
with self.assertRaises(OSError) as cm:
|
with self.assertRaises(OSError) as cm:
|
||||||
p.mkdir()
|
p.mkdir()
|
||||||
self.assertEqual(cm.exception.errno, errno.EEXIST)
|
self.assertEqual(cm.exception.errno, errno.EEXIST)
|
||||||
# XXX test `mode` arg
|
|
||||||
|
|
||||||
def test_mkdir_parents(self):
|
def test_mkdir_parents(self):
|
||||||
# Creating a chain of directories
|
# Creating a chain of directories
|
||||||
|
@ -1493,7 +1492,17 @@ class _BasePathTest(object):
|
||||||
with self.assertRaises(OSError) as cm:
|
with self.assertRaises(OSError) as cm:
|
||||||
p.mkdir(parents=True)
|
p.mkdir(parents=True)
|
||||||
self.assertEqual(cm.exception.errno, errno.EEXIST)
|
self.assertEqual(cm.exception.errno, errno.EEXIST)
|
||||||
# XXX test `mode` arg
|
# test `mode` arg
|
||||||
|
mode = stat.S_IMODE(p.stat().st_mode) # default mode
|
||||||
|
p = self.cls(BASE, 'newdirD', 'newdirE')
|
||||||
|
p.mkdir(0o555, parents=True)
|
||||||
|
self.assertTrue(p.exists())
|
||||||
|
self.assertTrue(p.is_dir())
|
||||||
|
if os.name != 'nt':
|
||||||
|
# the directory's permissions follow the mode argument
|
||||||
|
self.assertEqual(stat.S_IMODE(p.stat().st_mode), 0o555 & mode)
|
||||||
|
# the parent's permissions follow the default process settings
|
||||||
|
self.assertEqual(stat.S_IMODE(p.parent.stat().st_mode), mode)
|
||||||
|
|
||||||
@with_symlinks
|
@with_symlinks
|
||||||
def test_symlink_to(self):
|
def test_symlink_to(self):
|
||||||
|
|
|
@ -44,6 +44,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #19921: When Path.mkdir() is called with parents=True, any missing
|
||||||
|
parent is created with the default permissions, ignoring the mode argument
|
||||||
|
(mimicking the POSIX "mkdir -p" command).
|
||||||
|
|
||||||
- Issue #19887: Improve the Path.resolve() algorithm to support certain
|
- Issue #19887: Improve the Path.resolve() algorithm to support certain
|
||||||
symlink chains.
|
symlink chains.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue