kopia lustrzana https://github.com/micropython/micropython-lib
os: makedirs(): Rewrite to rely only on uos.mkdir().
rodzic
69ab21b6fc
commit
eb0981496a
|
@ -92,19 +92,21 @@ def rmdir(name):
|
||||||
check_error(e)
|
check_error(e)
|
||||||
|
|
||||||
def makedirs(name, mode=0o777, exist_ok=False):
|
def makedirs(name, mode=0o777, exist_ok=False):
|
||||||
exists = access(name, F_OK)
|
|
||||||
if exists:
|
|
||||||
if exist_ok:
|
|
||||||
return
|
|
||||||
raise OSError(errno_.EEXIST)
|
|
||||||
s = ""
|
s = ""
|
||||||
for c in name.split("/"):
|
comps = name.split("/")
|
||||||
|
if comps[-1] == "":
|
||||||
|
comps.pop()
|
||||||
|
for i, c in enumerate(comps):
|
||||||
s += c + "/"
|
s += c + "/"
|
||||||
try:
|
try:
|
||||||
mkdir(s)
|
uos.mkdir(s)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.args[0] != errno_.EEXIST:
|
if e.args[0] != errno_.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
if i == len(comps) - 1:
|
||||||
|
if exist_ok:
|
||||||
|
return
|
||||||
|
raise e
|
||||||
|
|
||||||
if hasattr(uos, "ilistdir"):
|
if hasattr(uos, "ilistdir"):
|
||||||
ilistdir = uos.ilistdir
|
ilistdir = uos.ilistdir
|
||||||
|
|
Ładowanie…
Reference in New Issue