File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments