@@ -206,23 +206,16 @@ def _add(str, fn):
206206SEEK_CUR = 1
207207SEEK_END = 2
208208
209-
210- def _get_masked_mode (mode ):
211- mask = umask (0 )
212- umask (mask )
213- return mode & ~ mask
214-
215209# Super directory utilities.
216210# (Inspired by Eric Raymond; the doc strings are mostly his)
217211
218212def makedirs (name , mode = 0o777 , exist_ok = False ):
219213 """makedirs(name [, mode=0o777][, exist_ok=False])
220214
221- Super-mkdir; create a leaf directory and all intermediate ones.
222- Works like mkdir, except that any intermediate path segment (not
223- just the rightmost) will be created if it does not exist. If the
224- target directory with the same mode as we specified already exists,
225- raises an OSError if exist_ok is False, otherwise no exception is
215+ Super-mkdir; create a leaf directory and all intermediate ones. Works like
216+ mkdir, except that any intermediate path segment (not just the rightmost)
217+ will be created if it does not exist. If the target directory already
218+ exists, raise an OSError if exist_ok is False. Otherwise no exception is
226219 raised. This is recursive.
227220
228221 """
@@ -243,20 +236,7 @@ def makedirs(name, mode=0o777, exist_ok=False):
243236 try :
244237 mkdir (name , mode )
245238 except OSError as e :
246- dir_exists = path .isdir (name )
247- expected_mode = _get_masked_mode (mode )
248- if dir_exists :
249- # S_ISGID is automatically copied by the OS from parent to child
250- # directories on mkdir. Don't consider it being set to be a mode
251- # mismatch as mkdir does not unset it when not specified in mode.
252- actual_mode = st .S_IMODE (lstat (name ).st_mode ) & ~ st .S_ISGID
253- else :
254- actual_mode = - 1
255- if not (e .errno == errno .EEXIST and exist_ok and dir_exists and
256- actual_mode == expected_mode ):
257- if dir_exists and actual_mode != expected_mode :
258- e .strerror += ' (mode %o != expected mode %o)' % (
259- actual_mode , expected_mode )
239+ if not exist_ok or e .errno != errno .EEXIST or not path .isdir (name ):
260240 raise
261241
262242def removedirs (name ):
0 commit comments