Index: Lib/shutil.py =================================================================== --- Lib/shutil.py (revision 87564) +++ Lib/shutil.py (working copy) @@ -280,6 +280,10 @@ real_dst = os.path.join(dst, _basename(src)) if os.path.exists(real_dst): raise Error, "Destination path '%s' already exists" % real_dst + + src_targetname = src.split(os.sep)[-1] + dst_targetname = real_dst.split(os.sep)[-1] + try: os.rename(src, real_dst) except OSError: @@ -287,10 +291,12 @@ if _destinsrc(src, dst): raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst) copytree(src, real_dst, symlinks=True) - rmtree(src) + if not (src_targetname.lower() == dst_targetname.lower()): + rmtree(src) else: copy2(src, real_dst) - os.unlink(src) + if not (src_targetname.lower() == dst_targetname.lower()): + os.unlink(src) def _destinsrc(src, dst): src = abspath(src) Index: Lib/test/test_shutil.py =================================================================== --- Lib/test/test_shutil.py (revision 87564) +++ Lib/test/test_shutil.py (working copy) @@ -20,6 +20,8 @@ TESTFN2 = TESTFN + "2" +CASEINSENSITIVE_FS = ['mac','darwin','win32'] + try: import grp import pwd @@ -639,6 +641,16 @@ except: pass + + @unittest.skipUnless(sys.platform in CASEINSENSITIVE_FS, + "Applicable only to case-sensitive filesystem") + def test_move_dir_caseinsensitivefs(self): + # Move a dir to another location on a case insensitive filesystem. + src = self.src_file + dest = src.upper() + shutil.move(src, dest) + self.assertTrue(os.path.exists(dest)) + def test_move_dir_other_fs(self): # Move a dir to another location on another filesystem. if not self.dir_other_fs: