Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for filtering the hardlink targed
  • Loading branch information
encukou committed Jun 23, 2026
commit 4318869913d426acb1eb7bd0ea58b3181dd38d15
19 changes: 19 additions & 0 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4403,6 +4403,25 @@ def test_chown_links_on_extractall(self):
])
mock_lchown.assert_not_called()

def test_extract_filters_target(self):
# Test that when extract() falls back to extracting (rather than
# linking) a hardlink target, it filters the target.
with ArchiveMaker() as arc:
arc.add("target")
arc.add("link", hardlink_to="target")
def testing_filter(member, path):
if member.name == 'target':
# target: set read-only
return member.replace(mode=stat.S_IRUSR)
# link: don't overwrite the mode
return member.replace(mode=None)
tempdir = pathlib.Path(TEMPDIR) / 'extract'
with os_helper.temp_dir(tempdir), arc.open() as tar:
tar.extract("link", path=tempdir, filter=testing_filter)
path = tempdir / 'link'
if os_helper.can_chmod():
self.assertFalse(path.stat().st_mode & stat.S_IWUSR)

def test_link_fallback_normalizes(self):
# Make sure hardlink fallbacks work for non-normalized paths for all
# filters
Expand Down