Index: Lib/shutil.py =================================================================== --- Lib/shutil.py (revision 85121) +++ Lib/shutil.py (working copy) @@ -317,7 +317,11 @@ try: os.rename(src, real_dst) except OSError: - if os.path.isdir(src): + if os.path.islink(src): + linkto = os.readlink(src) + os.symlink(linkto, real_dst) + os.unlink(src) + elif os.path.isdir(src): if _destinsrc(src, dst): raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst)) copytree(src, real_dst, symlinks=True) Index: Lib/test/test_shutil.py =================================================================== --- Lib/test/test_shutil.py (revision 85121) +++ Lib/test/test_shutil.py (working copy) @@ -798,7 +798,49 @@ finally: shutil.rmtree(TESTFN, ignore_errors=True) + @support.skip_unless_symlink + def test_move_file_symlink_other_fs(self): + filename = "bar" + dst = os.path.join(self.src_dir, filename) + os.symlink(self.src_file, dst) + shutil.move(dst, self.file_other_fs) + self.assertTrue(os.path.islink(self.file_other_fs)) + self.assertTrue(os.path.samefile(self.src_file, self.file_other_fs)) + @support.skip_unless_symlink + def test_move_file_symlink_to_dir_other_fs(self): + filename = "bar" + dst = os.path.join(self.src_dir, filename) + os.symlink(self.src_file, dst) + shutil.move(dst, self.dir_other_fs) + final_link = os.path.join(self.dir_other_fs, filename) + self.assertTrue(os.path.islink(final_link)) + self.assertTrue(os.path.samefile(self.src_file, final_link)) + + @support.skip_unless_symlink + def test_move_dangling_symlink_other_fs(self): + filename = "bar" + srcfilename = "baz" + src = os.path.join(self.src_dir, srcfilename) + dst = os.path.join(self.src_dir, filename) + os.symlink(src, dst) + shutil.move(dst, self.file_other_fs) + self.assertTrue(os.path.islink(self.file_other_fs)) + self.assertEqual(src, os.path.realpath(self.file_other_fs)) + + @support.skip_unless_symlink + def test_move_dir_symlink_other_fs(self): + filename = "bar" + srcfilename = "baz" + src = os.path.join(self.src_dir, srcfilename) + dst = os.path.join(self.src_dir, filename) + os.mkdir(src) + os.symlink(src, dst) + shutil.move(dst, self.file_other_fs) + self.assertTrue(os.path.islink(self.file_other_fs)) + self.assertTrue(os.path.samefile(src, self.file_other_fs)) + + class TestCopyFile(unittest.TestCase): _delete = False