[Python-checkins] cpython (merge 3.3 -> default): Issue #19856: shutil.move() failed to move a directory to other directory

serhiy.storchaka python-checkins at python.org
Tue Feb 11 09:41:18 CET 2014


http://hg.python.org/cpython/rev/41610ad5c755
changeset:   89140:41610ad5c755
parent:      89130:cdaf7b38bb2c
parent:      89139:373ec8711ad0
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Tue Feb 11 10:32:41 2014 +0200
summary:
  Issue #19856: shutil.move() failed to move a directory to other directory
on Windows if source name ends with os.altsep.

files:
  Lib/shutil.py           |  3 ++-
  Lib/test/test_shutil.py |  9 +++++++++
  Misc/NEWS               |  3 +++
  3 files changed, 14 insertions(+), 1 deletions(-)


diff --git a/Lib/shutil.py b/Lib/shutil.py
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -483,7 +483,8 @@
 def _basename(path):
     # A basename() variant which first strips the trailing slash, if present.
     # Thus we always get the last component of the path, even for directories.
-    return os.path.basename(path.rstrip(os.path.sep))
+    sep = os.path.sep + (os.path.altsep or '')
+    return os.path.basename(path.rstrip(sep))
 
 def move(src, dst):
     """Recursively move a file or directory to another location. This is
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
@@ -1492,6 +1492,15 @@
         # Move a dir inside an existing dir on another filesystem.
         self.test_move_dir_to_dir()
 
+    def test_move_dir_sep_to_dir(self):
+        self._check_move_dir(self.src_dir + os.path.sep, self.dst_dir,
+            os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
+
+    @unittest.skipUnless(os.path.altsep, 'requires os.path.altsep')
+    def test_move_dir_altsep_to_dir(self):
+        self._check_move_dir(self.src_dir + os.path.altsep, self.dst_dir,
+            os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
+
     def test_existing_file_inside_dest_dir(self):
         # A file with the same name inside the destination dir already exists.
         with open(self.dst_file, "wb"):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@
 Library
 -------
 
+- Issue #19856: shutil.move() failed to move a directory to other directory
+  on Windows if source name ends with os.altsep.
+
 - Issue #20530: The signatures for slot builtins have been updated
   to reflect the fact that they only accept positional-only arguments.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list