shutil: Fix shutil.rmtree to use os.ilistdir instead of os.walk.

pull/574/head
Brian Pugh 2022-11-10 08:04:49 -08:00 zatwierdzone przez Damien George
rodzic ee286ed28c
commit 4ae896afdc
1 zmienionych plików z 8 dodań i 5 usunięć

Wyświetl plik

@ -5,11 +5,14 @@ from collections import namedtuple
_ntuple_diskusage = namedtuple("usage", ("total", "used", "free")) _ntuple_diskusage = namedtuple("usage", ("total", "used", "free"))
def rmtree(top): def rmtree(d):
for path, dirs, files in os.walk(top, False): for name, type, *_ in os.ilistdir(d):
for f in files: path = d + "/" + name
os.unlink(path + "/" + f) if type & 0x4000: # dir
os.rmdir(path) rmtree(path)
else: # file
os.unlink(path)
os.rmdir(d)
def copyfileobj(src, dest, length=512): def copyfileobj(src, dest, length=512):