mirror of
https://github.com/python/cpython.git
synced 2025-01-18 14:35:37 +08:00
merge from 3.1
This commit is contained in:
commit
78349b06af
@ -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))
|
||||
|
@ -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)
|
||||
|
@ -596,6 +596,10 @@ Library
|
||||
and a non-zero offset, and an attempt to read past the end of file is made
|
||||
(IndexError is raised instead). Patch by Ross Lagerwall.
|
||||
|
||||
- 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 #10907: Warn OS X 10.6 IDLE users to use ActiveState Tcl/Tk 8.5, rather
|
||||
than the currently problematic Apple-supplied one, when running with the
|
||||
64-/32-bit installer variant.
|
||||
|
Loading…
Reference in New Issue
Block a user