This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: shutil.rmtree is inefficient because of using os.scandir instead of os.walk
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Felipe A. Hernandez
Priority: normal Keywords:

Created on 2020-01-07 14:36 by Felipe A. Hernandez, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg359512 - (view) Author: Felipe A. Hernandez (Felipe A. Hernandez) Date: 2020-01-07 14:36
os.rmtree has fd-based symlink replacement protection when iterating with scandir (after bpo-28564).

This logic could be greatly simplified simply by os.fwalk in supported platforms, which already implements a similar (maybe safer) protection.
msg359570 - (view) Author: Felipe A. Hernandez (Felipe A. Hernandez) Date: 2020-01-08 08:47
After some tests, due the accumulating nature of fwalk, I've just realised it's not very safe for big directories, so I'll be closing this issue.

Alternatively, using py37+ fd based scandir, and dir_fd unlink and rmdir calls would reduce complexity while improving safety.

Sorry for the noise.
History
Date User Action Args
2022-04-11 14:59:25adminsetgithub: 83427
2020-01-08 08:47:43Felipe A. Hernandezsetstatus: open -> closed
resolution: not a bug
messages: + msg359570

stage: resolved
2020-01-07 14:36:26Felipe A. Hernandezcreate