diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-11 08:32:41 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-11 08:32:41 (GMT) |
commit | 6a45021084f287cf389205939784d32f29efb20c (patch) | |
tree | 5ae62310475dd8f07c68f716bdd452b7fee6a8c8 | |
parent | 42ec031fe75601710b4edbfe7e617b97b4948de6 (diff) | |
parent | 3a308b9f374da7f11df888f104dae6464e81d73d (diff) | |
download | cpython-6a45021084f287cf389205939784d32f29efb20c.zip cpython-6a45021084f287cf389205939784d32f29efb20c.tar.gz cpython-6a45021084f287cf389205939784d32f29efb20c.tar.bz2 |
Issue #19856: shutil.move() failed to move a directory to other directory
on Windows if source name ends with os.altsep.
-rw-r--r-- | Lib/shutil.py | 3 | ||||
-rw-r--r-- | Lib/test/test_shutil.py | 9 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 14 insertions, 1 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 9a6a040..0cd6ec4 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -483,7 +483,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 1f47b03..a483fe1 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1492,6 +1492,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"): @@ -37,6 +37,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 #20530: The signatures for slot builtins have been updated to reflect the fact that they only accept positional-only arguments. |