summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRonald Oussoren <ronaldoussoren@mac.com>2011-05-06 09:17:40 (GMT)
committerRonald Oussoren <ronaldoussoren@mac.com>2011-05-06 09:17:40 (GMT)
commit136148e97d514291ac027dfb0c036f158fe47389 (patch)
tree017ce8cd9ffcf769961248bbd596fa5c227d4317 /Lib
parentf804f3a507834faae4a2305079077adb0f802283 (diff)
parent78349b06af6cabe7ff949a98fafa15d8a9c48c61 (diff)
downloadcpython-136148e97d514291ac027dfb0c036f158fe47389.zip
cpython-136148e97d514291ac027dfb0c036f158fe47389.tar.gz
cpython-136148e97d514291ac027dfb0c036f158fe47389.tar.bz2
merge from 3.2
Diffstat (limited to 'Lib')
-rw-r--r--Lib/shutil.py8
-rw-r--r--Lib/test/test_shutil.py18
2 files changed, 25 insertions, 1 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index aafe04e..d2e2dc5 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -311,12 +311,18 @@ 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)
try:
os.rename(src, real_dst)
- except OSError:
+ except OSError as exc:
if os.path.isdir(src):
if _destinsrc(src, dst):
raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 5252d4d..475a26b 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -951,6 +951,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():
support.run_unittest(TestShutil, TestMove, TestCopyFile)