]> granicus.if.org Git - python/commitdiff
Issue #19856: shutil.move() failed to move a directory to other directory
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 11 Feb 2014 08:30:06 +0000 (10:30 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 11 Feb 2014 08:30:06 +0000 (10:30 +0200)
on Windows if source name ends with os.altsep.

Lib/shutil.py
Lib/test/test_shutil.py
Misc/NEWS

index f8f0b7d843f5490ef452b37ad9f97318dea9e60e..e12f791fd1db23b82ab96debdeee57ceee9b6310 100644 (file)
@@ -259,7 +259,8 @@ def rmtree(path, ignore_errors=False, onerror=None):
 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
index 8160f41bff40bd56a679ca7756e7c9a53ede4b9b..0e811459fce246704b77b5317fb9c02ae0457162 100644 (file)
@@ -698,6 +698,15 @@ class TestMove(unittest.TestCase):
         self._check_move_dir(self.src_dir, self.dir_other_fs,
             os.path.join(self.dir_other_fs, os.path.basename(self.src_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"):
index f63d2a6c6064069a1308371b877bc03da62af4de..38d863081cb76eb2647b90abb313349eb4f98374 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #19856: shutil.move() failed to move a directory to other directory
+  on Windows if source name ends with os.altsep.
+
 - Issue #14983: email.generator now always adds a line end after each MIME
   boundary marker, instead of doing so only when there is an epilogue.  This
   fixes an RFC compliance bug and solves an issue with signed MIME parts.