summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-06-25 11:27:31 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-06-25 11:27:31 (GMT)
commit3b52778c74f0290e6103a6381ff9189f6b8c5e51 (patch)
treef00f37e9fc9d60359b20262a0ad557e7517030a7 /Lib
parent77892dc1e3b8d145b1ce22ae6129e80ee07f027f (diff)
downloadcpython-3b52778c74f0290e6103a6381ff9189f6b8c5e51.zip
cpython-3b52778c74f0290e6103a6381ff9189f6b8c5e51.tar.gz
cpython-3b52778c74f0290e6103a6381ff9189f6b8c5e51.tar.bz2
#4489 Make fd based rmtree work on bytes
Diffstat (limited to 'Lib')
-rw-r--r--Lib/shutil.py3
-rw-r--r--Lib/test/test_shutil.py9
2 files changed, 12 insertions, 0 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 2c00f4a..3cafd01 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -426,6 +426,9 @@ def rmtree(path, ignore_errors=False, onerror=None):
def onerror(*args):
raise
if _use_fd_functions:
+ # While the unsafe rmtree works fine on bytes, the fd based does not.
+ if isinstance(path, bytes):
+ path = os.fsdecode(path)
# Note: To guard against symlink races, we use the standard
# lstat()/open()/fstat() trick.
try:
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index c879fdd..d23deee 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -108,6 +108,15 @@ class TestShutil(unittest.TestCase):
self.tempdirs.append(d)
return d
+ def test_rmtree_works_on_bytes(self):
+ tmp = self.mkdtemp()
+ victim = os.path.join(tmp, 'killme')
+ os.mkdir(victim)
+ write_file(os.path.join(victim, 'somefile'), 'foo')
+ victim = os.fsencode(victim)
+ self.assertIsInstance(victim, bytes)
+ shutil.rmtree(victim)
+
def test_rmtree_errors(self):
# filename is guaranteed not to exist
filename = tempfile.mktemp()