Skip to content

Commit eb09814

Browse files
committed
os: makedirs(): Rewrite to rely only on uos.mkdir().
1 parent 69ab21b commit eb09814

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

os/os/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,21 @@ def rmdir(name):
9292
check_error(e)
9393

9494
def makedirs(name, mode=0o777, exist_ok=False):
95-
exists = access(name, F_OK)
96-
if exists:
97-
if exist_ok:
98-
return
99-
raise OSError(errno_.EEXIST)
10095
s = ""
101-
for c in name.split("/"):
96+
comps = name.split("/")
97+
if comps[-1] == "":
98+
comps.pop()
99+
for i, c in enumerate(comps):
102100
s += c + "/"
103101
try:
104-
mkdir(s)
102+
uos.mkdir(s)
105103
except OSError as e:
106104
if e.args[0] != errno_.EEXIST:
107105
raise
106+
if i == len(comps) - 1:
107+
if exist_ok:
108+
return
109+
raise e
108110

109111
if hasattr(uos, "ilistdir"):
110112
ilistdir = uos.ilistdir

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy