diff options
| author | Ronald Oussoren <ronaldoussoren@mac.com> | 2011-05-06 09:31:33 (GMT) |
|---|---|---|
| committer | Ronald Oussoren <ronaldoussoren@mac.com> | 2011-05-06 09:31:33 (GMT) |
| commit | 58d6b1b7a4f25d09991d5bf853d7c23c7545f01b (patch) | |
| tree | 3e31c1e2a4e695bdb40928c34e65041801706c6d | |
| parent | fe12aa67fc93ddc97fce2ecb856eef6545efd98b (diff) | |
| download | cpython-58d6b1b7a4f25d09991d5bf853d7c23c7545f01b.zip cpython-58d6b1b7a4f25d09991d5bf853d7c23c7545f01b.tar.gz cpython-58d6b1b7a4f25d09991d5bf853d7c23c7545f01b.tar.bz2 | |
Backport fix for issue #10684 from 3.x
| -rw-r--r-- | Lib/shutil.py | 6 | ||||
| -rw-r--r-- | Lib/test/test_shutil.py | 18 | ||||
| -rw-r--r-- | Misc/NEWS | 4 |
3 files changed, 28 insertions, 0 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index f2d2a90..9d922fb 100644 --- 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): + # We might be on a case insensitive filesystem, + # perform the rename anyway. + os.rename(src, dst) + return + real_dst = os.path.join(dst, _basename(src)) if os.path.exists(real_dst): raise Error, "Destination path '%s' already exists" % real_dst diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index fdc0bc1..9f9bf45 100644 --- 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 + # but a different case. + + self.src_dir = tempfile.mkdtemp() + dst_dir = os.path.join( + os.path.dirname(self.src_dir), + os.path.basename(self.src_dir).upper()) + self.assertNotEqual(self.src_dir, dst_dir) + + try: + shutil.move(self.src_dir, dst_dir) + self.assertTrue(os.path.isdir(dst_dir)) + finally: + if os.path.exists(dst_dir): + os.rmdir(dst_dir) + + def test_main(): test_support.run_unittest(TestShutil, TestMove, TestCopyFile) @@ -77,6 +77,10 @@ Core and Builtins Library ------- +- Issue #10684: shutil.move used to delete a folder on case insensitive + filesystems when the source and destination name where the same except + for the case. + - Issue #11982: fix json.loads('""') to return u'' rather than ''. - Issue #11277: mmap.mmap() calls fcntl(fd, F_FULLFSYNC) on Mac OS X to get |
