mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-113188: Fix shutil.copymode() on Windows (GH-113189)
Previously it worked differently if dst is a symbolic link: it modified the permission bits of dst itself rather than the file it points to if follow_symlinks is true or src is not a symbolic link, and did nothing if follow_symlinks is false and src is a symbolic link. Also document similar changes in shutil.copystat().
This commit is contained in:
parent
bdc8d667ab
commit
6e02d79f96
3 changed files with 24 additions and 14 deletions
|
@ -1101,19 +1101,18 @@ class TestCopy(BaseTest, unittest.TestCase):
|
|||
shutil.copymode(src, dst)
|
||||
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
|
||||
# On Windows, os.chmod does not follow symlinks (issue #15411)
|
||||
if os.name != 'nt':
|
||||
# follow src link
|
||||
os.chmod(dst, stat.S_IRWXO)
|
||||
shutil.copymode(src_link, dst)
|
||||
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
|
||||
# follow dst link
|
||||
os.chmod(dst, stat.S_IRWXO)
|
||||
shutil.copymode(src, dst_link)
|
||||
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
|
||||
# follow both links
|
||||
os.chmod(dst, stat.S_IRWXO)
|
||||
shutil.copymode(src_link, dst_link)
|
||||
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
|
||||
# follow src link
|
||||
os.chmod(dst, stat.S_IRWXO)
|
||||
shutil.copymode(src_link, dst)
|
||||
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
|
||||
# follow dst link
|
||||
os.chmod(dst, stat.S_IRWXO)
|
||||
shutil.copymode(src, dst_link)
|
||||
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
|
||||
# follow both links
|
||||
os.chmod(dst, stat.S_IRWXO)
|
||||
shutil.copymode(src_link, dst_link)
|
||||
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod')
|
||||
@os_helper.skip_unless_symlink
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue