A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/commit/ee5f1c13d1ea21c628068fdf142823177f5526c2 below:

remove directory mode check from makedirs (closes #21082) · python/cpython@ee5f1c1 · GitHub

File tree Expand file treeCollapse file tree 4 files changed

+20

-32

lines changed

Filter options

Expand file treeCollapse file tree 4 files changed

+20

-32

lines changed Original file line number Diff line number Diff line change

@@ -1188,11 +1188,8 @@ Files and Directories

1188 1188

The default *mode* is ``0o777`` (octal). On some systems, *mode* is

1189 1189

ignored. Where it is used, the current umask value is first masked out.

1190 1190 1191 -

If *exists_ok* is ``False`` (the default), an :exc:`OSError` is raised if

1192 -

the target directory already exists. If *exists_ok* is ``True`` an

1193 -

:exc:`OSError` is still raised if the umask-masked *mode* is different from

1194 -

the existing mode, on systems where the mode is used. :exc:`OSError` will

1195 -

also be raised if the directory creation fails.

1191 +

If *exist_ok* is ``False`` (the default), an :exc:`OSError` is raised if the

1192 +

target directory already exists.

1196 1193 1197 1194

.. note::

1198 1195

@@ -1204,6 +1201,13 @@ Files and Directories

1204 1201

.. versionadded:: 3.2

1205 1202

The *exist_ok* parameter.

1206 1203 1204 +

.. versionchanged:: 3.2.5

1205 + 1206 +

Before Python 3.2.5, if *exist_ok* was ``True`` and the directory existed,

1207 +

:func:`makedirs` would still raise an error if *mode* did not match the

1208 +

mode of the existing directory. Since this behavior was impossible to

1209 +

implement safely, it was removed in Python 3.2.6. See :issue:`21082`.

1210 + 1207 1211 1208 1212

.. function:: pathconf(path, name)

1209 1213 Original file line number Diff line number Diff line change

@@ -114,12 +114,6 @@ def _get_exports_list(module):

114 114

SEEK_CUR = 1

115 115

SEEK_END = 2

116 116 117 - 118 -

def _get_masked_mode(mode):

119 -

mask = umask(0)

120 -

umask(mask)

121 -

return mode & ~mask

122 - 123 117

#'

124 118 125 119

# Super directory utilities.

@@ -128,11 +122,10 @@ def _get_masked_mode(mode):

128 122

def makedirs(name, mode=0o777, exist_ok=False):

129 123

"""makedirs(path [, mode=0o777][, exist_ok=False])

130 124 131 -

Super-mkdir; create a leaf directory and all intermediate ones.

132 -

Works like mkdir, except that any intermediate path segment (not

133 -

just the rightmost) will be created if it does not exist. If the

134 -

target directory with the same mode as we specified already exists,

135 -

raises an OSError if exist_ok is False, otherwise no exception is

125 +

Super-mkdir; create a leaf directory and all intermediate ones. Works like

126 +

mkdir, except that any intermediate path segment (not just the rightmost)

127 +

will be created if it does not exist. If the target directory already

128 +

exists, raise an OSError if exist_ok is False. Otherwise no exception is

136 129

raised. This is recursive.

137 130 138 131

"""

@@ -154,18 +147,7 @@ def makedirs(name, mode=0o777, exist_ok=False):

154 147

try:

155 148

mkdir(name, mode)

156 149

except OSError as e:

157 -

import stat as st

158 -

dir_exists = path.isdir(name)

159 -

expected_mode = _get_masked_mode(mode)

160 -

if dir_exists:

161 -

# S_ISGID is automatically copied by the OS from parent to child

162 -

# directories on mkdir. Don't consider it being set to be a mode

163 -

# mismatch as mkdir does not unset it when not specified in mode.

164 -

actual_mode = st.S_IMODE(lstat(name).st_mode) & ~st.S_ISGID

165 -

else:

166 -

actual_mode = -1

167 -

if not (e.errno == errno.EEXIST and exist_ok and dir_exists and

168 -

actual_mode == expected_mode):

150 +

if not exist_ok or e.errno != errno.EEXIST or not path.isdir(name):

169 151

raise

170 152 171 153

def removedirs(name):

Original file line number Diff line number Diff line change

@@ -579,7 +579,7 @@ def test_exist_ok_existing_directory(self):

579 579

os.makedirs(path, mode)

580 580

self.assertRaises(OSError, os.makedirs, path, mode)

581 581

self.assertRaises(OSError, os.makedirs, path, mode, exist_ok=False)

582 -

self.assertRaises(OSError, os.makedirs, path, 0o776, exist_ok=True)

582 +

os.makedirs(path, 0o776, exist_ok=True)

583 583

os.makedirs(path, mode=mode, exist_ok=True)

584 584

finally:

585 585

os.umask(old_mask)

@@ -606,9 +606,8 @@ def test_exist_ok_s_isgid_directory(self):

606 606

os.makedirs(path, mode, exist_ok=True)

607 607

# remove the bit.

608 608

os.chmod(path, stat.S_IMODE(os.lstat(path).st_mode) & ~S_ISGID)

609 -

with self.assertRaises(OSError):

610 -

# Should fail when the bit is not already set when demanded.

611 -

os.makedirs(path, mode | S_ISGID, exist_ok=True)

609 +

# May work even when the bit is not already set when demanded.

610 +

os.makedirs(path, mode | S_ISGID, exist_ok=True)

612 611

finally:

613 612

os.umask(old_mask)

614 613 Original file line number Diff line number Diff line change

@@ -10,6 +10,9 @@ What's New in Python 3.2.6?

10 10

Library

11 11

-------

12 12 13 +

- Issue #21082: In os.makedirs, do not set the process-wide umask. Note this

14 +

changes behavior of makedirs when exist_ok=True.

15 + 13 16

- Issue #20246: Fix buffer overflow in socket.recvfrom_into.

14 17 15 18

- Issue #12226: HTTPS is now used by default when connecting to PyPI.

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4