From 658bdb5a03e56139971829fc6db5705f6aea623f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 10 Nov 2020 17:06:02 +0100 Subject: [PATCH] bpo-42014: shutil.rmtree: call onerror with correct function (GH-22585) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The onerror is supposed to be called with failed function, but in this case lstat is wrongly used instead of open. Not sure if this needs bug or not... Automerge-Triggered-By: GH:hynek (cherry picked from commit e59b2deffde61e5641cabd65034fa11b4db898ba) Co-authored-by: Michal Čihař --- Lib/shutil.py | 2 +- .../next/Library/2020-11-10-15-40-56.bpo-42014.ShM37l.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2020-11-10-15-40-56.bpo-42014.ShM37l.rst diff --git a/Lib/shutil.py b/Lib/shutil.py index 9d151493e76675..6986bce8aaee2d 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -711,7 +711,7 @@ def onerror(*args): try: fd = os.open(path, os.O_RDONLY) except Exception: - onerror(os.lstat, path, sys.exc_info()) + onerror(os.open, path, sys.exc_info()) return try: if os.path.samestat(orig_st, os.fstat(fd)): diff --git a/Misc/NEWS.d/next/Library/2020-11-10-15-40-56.bpo-42014.ShM37l.rst b/Misc/NEWS.d/next/Library/2020-11-10-15-40-56.bpo-42014.ShM37l.rst new file mode 100644 index 00000000000000..d3e1abcd84c1e8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-11-10-15-40-56.bpo-42014.ShM37l.rst @@ -0,0 +1 @@ +The ``onerror`` callback from ``shutil.rmtree`` now receives correct function when ``os.open`` fails. \ No newline at end of file