kopia lustrzana https://github.com/micropython/micropython-lib
os: Refactor ilistdir() to be compatible with builtin uos.ilistdir().
rodzic
e9648dad01
commit
8884dbbee5
|
@ -122,7 +122,7 @@ def makedirs(name, mode=0o777, exist_ok=False):
|
||||||
if e.args[0] != errno.EEXIST:
|
if e.args[0] != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def ilistdir_ex(path="."):
|
def ilistdir(path="."):
|
||||||
dir = opendir_(path)
|
dir = opendir_(path)
|
||||||
if not dir:
|
if not dir:
|
||||||
raise_error()
|
raise_error()
|
||||||
|
@ -134,13 +134,14 @@ def ilistdir_ex(path="."):
|
||||||
break
|
break
|
||||||
dirent = ffi.as_bytearray(dirent, struct.calcsize(dirent_fmt))
|
dirent = ffi.as_bytearray(dirent, struct.calcsize(dirent_fmt))
|
||||||
dirent = struct.unpack(dirent_fmt, dirent)
|
dirent = struct.unpack(dirent_fmt, dirent)
|
||||||
|
dirent = (dirent[-1].split(b'\0', 1)[0], dirent[-2], dirent[0])
|
||||||
yield dirent
|
yield dirent
|
||||||
|
|
||||||
def listdir(path="."):
|
def listdir(path="."):
|
||||||
is_str = type(path) is not bytes
|
is_str = type(path) is not bytes
|
||||||
res = []
|
res = []
|
||||||
for dirent in ilistdir_ex(path):
|
for dirent in ilistdir(path):
|
||||||
fname = dirent[4].split(b'\0', 1)[0]
|
fname = dirent[0]
|
||||||
if fname != b"." and fname != b"..":
|
if fname != b"." and fname != b"..":
|
||||||
if is_str:
|
if is_str:
|
||||||
fname = fsdecode(fname)
|
fname = fsdecode(fname)
|
||||||
|
|
Ładowanie…
Reference in New Issue