]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport:
authorGuido van Rossum <guido@python.org>
Wed, 14 Jul 2004 00:48:02 +0000 (00:48 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 14 Jul 2004 00:48:02 +0000 (00:48 +0000)
- 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
Lib/test/test_shutil.py

index 10b7a277674a3e34cf3e4e0e8bcb14e62b9dc27f..fde8c90fe9fb596401ff0253135aa5280c4cba13 100644 (file)
@@ -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)
index 9a2be0ff83608d265288d9fc90b4101e89f96af5..164ccf8e618d8884953d389426ef15534607c82d 100644 (file)
@@ -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()