[Python-checkins] cpython (merge 3.2 -> default): merge from 3.2
ronald.oussoren
python-checkins at python.org
Fri May 6 11:32:04 CEST 2011
http://hg.python.org/cpython/rev/e781292fb65b
changeset: 69871:e781292fb65b
parent: 69868:c22d5b37f6a4
parent: 69870:f5aa0e52dd81
user: Ronald Oussoren <ronaldoussoren at mac.com>
date: Fri May 06 11:17:40 2011 +0200
summary:
merge from 3.2
files:
Lib/shutil.py | 8 +++++++-
Lib/test/test_shutil.py | 18 ++++++++++++++++++
Misc/NEWS | 4 ++++
3 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/Lib/shutil.py b/Lib/shutil.py
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -311,12 +311,18 @@
"""
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
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -951,6 +951,24 @@
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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -140,6 +140,10 @@
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 #11647: objects created using contextlib.contextmanager now support
more than one call to the function when used as a decorator. Initial patch
by Ysj Ray.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list