]> granicus.if.org Git - python/commitdiff
Backport fix for issue #10684 from 3.x
authorRonald Oussoren <ronaldoussoren@mac.com>
Fri, 6 May 2011 09:31:33 +0000 (11:31 +0200)
committerRonald Oussoren <ronaldoussoren@mac.com>
Fri, 6 May 2011 09:31:33 +0000 (11:31 +0200)
Lib/shutil.py
Lib/test/test_shutil.py
Misc/NEWS

index f2d2a90a8e5b76e5403758cfd3e706c78ecb8d2c..9d922fbefc3f4d8f3e09167e0d5a9df19cd39db0 100644 (file)
@@ -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
index fdc0bc1d8faeabe2f19feff194dca42beb976f48..9f9bf45e42daa24ea34a0e655e163866c77b68e3 100644 (file)
@@ -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)
index 743f10ac1b9d791ece5e05dffdbf9358b43c9eb1..bdecdf274432ca5617e482ae2067e7b0b4d06237 100644 (file)
--- 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
+  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