From 292b643ea7c4420950ec986c6b0856a13219b1e2 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 14 Jul 2004 00:48:02 +0000 Subject: Backport: - Bug #981530: Fix UnboundLocalError in shutil.rmtree(). This affects the documented behavior: the function passed to the onerror() handler can now also be os.listdir. [I could've sworn I checked this in, but apparently I didn't, or it got lost???] --- Lib/shutil.py | 1 + Lib/test/test_shutil.py | 1 + 2 files changed, 2 insertions(+) diff --git a/Lib/shutil.py b/Lib/shutil.py index 10b7a27..fde8c90 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -128,6 +128,7 @@ def rmtree(path, ignore_errors=False, onerror=None): cmdtuples = [] arg = path try: + func = os.listdir # Make sure it isn't unset _build_cmdtuple(path, cmdtuples) for func, arg in cmdtuples: func(arg) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 9a2be0f..164ccf8 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -13,6 +13,7 @@ class TestShutil(unittest.TestCase): filename = tempfile.mktemp() self.assertRaises(OSError, shutil.rmtree, filename) self.assertEqual(shutil.rmtree(filename, True), None) + shutil.rmtree(filename, False, lambda func, arg, exc: None) def test_dont_move_dir_in_itself(self): src_dir = tempfile.mkdtemp() -- cgit v0.12