Skip to content

Commit 4318869

Browse files
committed
Add test for filtering the hardlink targed
1 parent 5edbc2e commit 4318869

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lib/test/test_tarfile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,6 +4403,25 @@ def test_chown_links_on_extractall(self):
44034403
])
44044404
mock_lchown.assert_not_called()
44054405

4406+
def test_extract_filters_target(self):
4407+
# Test that when extract() falls back to extracting (rather than
4408+
# linking) a hardlink target, it filters the target.
4409+
with ArchiveMaker() as arc:
4410+
arc.add("target")
4411+
arc.add("link", hardlink_to="target")
4412+
def testing_filter(member, path):
4413+
if member.name == 'target':
4414+
# target: set read-only
4415+
return member.replace(mode=stat.S_IRUSR)
4416+
# link: don't overwrite the mode
4417+
return member.replace(mode=None)
4418+
tempdir = pathlib.Path(TEMPDIR) / 'extract'
4419+
with os_helper.temp_dir(tempdir), arc.open() as tar:
4420+
tar.extract("link", path=tempdir, filter=testing_filter)
4421+
path = tempdir / 'link'
4422+
if os_helper.can_chmod():
4423+
self.assertFalse(path.stat().st_mode & stat.S_IWUSR)
4424+
44064425
def test_link_fallback_normalizes(self):
44074426
# Make sure hardlink fallbacks work for non-normalized paths for all
44084427
# filters

0 commit comments

Comments
 (0)