cpython: 051190230254 (original) (raw)
Mercurial > cpython
changeset 69872:051190230254 2.7
Backport fix for issue #10684 from 3.x [#10684]
Ronald Oussoren ronaldoussoren@mac.com | |
---|---|
date | Fri, 06 May 2011 11:31:33 +0200 |
parents | 76a2354aa427 |
children | a0147a1f1776 |
files | Lib/shutil.py Lib/test/test_shutil.py Misc/NEWS |
diffstat | 3 files changed, 28 insertions(+), 0 deletions(-)[+] [-] Lib/shutil.py 6 Lib/test/test_shutil.py 18 Misc/NEWS 4 |
line wrap: on
line diff
--- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -277,6 +277,12 @@ def move(src, dst): """ real_dst = dst if os.path.isdir(dst):
if _samefile(src, dst):[](#l1.7)
# We might be on a case insensitive filesystem,[](#l1.8)
# perform the rename anyway.[](#l1.9)
os.rename(src, dst)[](#l1.10)
return[](#l1.11)
+ real_dst = os.path.join(dst, _basename(src)) if os.path.exists(real_dst): raise Error, "Destination path '%s' already exists" % real_dst
--- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -805,6 +805,24 @@ class TestCopyFile(unittest.TestCase): self.assertTrue(srcfile._exited_with[0] is None) self.assertTrue(srcfile._raised)
- def test_move_dir_caseinsensitive(self):
# Renames a folder to the same name[](#l2.8)
# but a different case.[](#l2.9)
self.src_dir = tempfile.mkdtemp()[](#l2.11)
dst_dir = os.path.join([](#l2.12)
os.path.dirname(self.src_dir),[](#l2.13)
os.path.basename(self.src_dir).upper())[](#l2.14)
self.assertNotEqual(self.src_dir, dst_dir)[](#l2.15)
try:[](#l2.17)
shutil.move(self.src_dir, dst_dir)[](#l2.18)
self.assertTrue(os.path.isdir(dst_dir))[](#l2.19)
finally:[](#l2.20)
if os.path.exists(dst_dir):[](#l2.21)
os.rmdir(dst_dir)[](#l2.22)
+ + def test_main(): test_support.run_unittest(TestShutil, TestMove, TestCopyFile)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,10 @@ Core and Builtins Library ------- +- Issue #10684: shutil.move used to delete a folder on case insensitive