From: Serhiy Storchaka Date: Tue, 11 Feb 2014 08:30:59 +0000 (+0200) Subject: Issue #19856: shutil.move() failed to move a directory to other directory X-Git-Tag: v3.3.5rc1^2~36 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a308b9f374da7f11df888f104dae6464e81d73d;p=python Issue #19856: shutil.move() failed to move a directory to other directory on Windows if source name ends with os.altsep. --- diff --git a/Lib/shutil.py b/Lib/shutil.py index 5320f23646..5a4d4f6e79 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -484,7 +484,8 @@ rmtree.avoids_symlink_attacks = _use_fd_functions 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 index ac00cc438d..c3fb8a7d2c 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1481,6 +1481,15 @@ class TestMove(unittest.TestCase): # 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 index ac1ba0da2b..647cedf34e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -20,6 +20,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.