Skip to content

Commit b672888

Browse files
committed
Issue python#20055: Fix test_shutil under Windows with symlink privileges held.
Patch by Vajrasky Kok.
2 parents 089305f + 3f48ac9 commit b672888

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

‎Lib/test/test_shutil.py‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,20 @@ def test_copymode_follow_symlinks(self):
288288
self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
289289
shutil.copymode(src, dst)
290290
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
291-
# follow src link
292-
os.chmod(dst, stat.S_IRWXO)
293-
shutil.copymode(src_link, dst)
294-
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
295-
# follow dst link
296-
os.chmod(dst, stat.S_IRWXO)
297-
shutil.copymode(src, dst_link)
298-
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
299-
# follow both links
300-
os.chmod(dst, stat.S_IRWXO)
301-
shutil.copymode(src_link, dst)
302-
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
291+
# On Windows, os.chmod does not follow symlinks (issue #15411)
292+
if os.name != 'nt':
293+
# follow src link
294+
os.chmod(dst, stat.S_IRWXO)
295+
shutil.copymode(src_link, dst)
296+
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
297+
# follow dst link
298+
os.chmod(dst, stat.S_IRWXO)
299+
shutil.copymode(src, dst_link)
300+
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
301+
# follow both links
302+
os.chmod(dst, stat.S_IRWXO)
303+
shutil.copymode(src_link, dst_link)
304+
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
303305

304306
@unittest.skipUnless(hasattr(os, 'lchmod'), 'requires os.lchmod')
305307
@support.skip_unless_symlink
@@ -1554,7 +1556,11 @@ def test_move_dangling_symlink(self):
15541556
dst_link = os.path.join(self.dst_dir, 'quux')
15551557
shutil.move(dst, dst_link)
15561558
self.assertTrue(os.path.islink(dst_link))
1557-
self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link))
1559+
# On Windows, os.path.realpath does not follow symlinks (issue #9949)
1560+
if os.name == 'nt':
1561+
self.assertEqual(os.path.realpath(src), os.readlink(dst_link))
1562+
else:
1563+
self.assertEqual(os.path.realpath(src), os.path.realpath(dst_link))
15581564

15591565
@support.skip_unless_symlink
15601566
@mock_rename

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ IDLE
267267
Tests
268268
-----
269269

270+
- Issue #20055: Fix test_shutil under Windows with symlink privileges held.
271+
Patch by Vajrasky Kok.
272+
270273
- Issue #20070: Don't run test_urllib2net when network resources are not
271274
enabled.
272275

0 commit comments

Comments
 (0)