@@ -3530,6 +3530,39 @@ class TestExtractionFilters(unittest.TestCase):
35303530 # The destination for the extraction, within `outerdir`
35313531 destdir = outerdir / 'dest'
35323532
3533+ @classmethod
3534+ def setUpClass (cls ):
3535+ # Posix and Windows have different pathname resolution:
3536+ # either symlink or a '..' component resolve first.
3537+ # Let's see which we are on.
3538+ if os_helper .can_symlink ():
3539+ testpath = os .path .join (TEMPDIR , 'resolution_test' )
3540+ os .mkdir (testpath )
3541+
3542+ # testpath/current links to `.` which is all of:
3543+ # - `testpath`
3544+ # - `testpath/current`
3545+ # - `testpath/current/current`
3546+ # - etc.
3547+ os .symlink ('.' , os .path .join (testpath , 'current' ))
3548+
3549+ # we'll test where `testpath/current/../file` ends up
3550+ with open (os .path .join (testpath , 'current' , '..' , 'file' ), 'w' ):
3551+ pass
3552+
3553+ if os .path .exists (os .path .join (testpath , 'file' )):
3554+ # Windows collapses 'current\..' to '.' first, leaving
3555+ # 'testpath\file'
3556+ cls .dotdot_resolves_early = True
3557+ elif os .path .exists (os .path .join (testpath , '..' , 'file' )):
3558+ # Posix resolves 'current' to '.' first, leaving
3559+ # 'testpath/../file'
3560+ cls .dotdot_resolves_early = False
3561+ else :
3562+ raise AssertionError ('Could not determine link resolution' )
3563+ else :
3564+ cls .dotdot_resolves_early = False
3565+
35333566 @contextmanager
35343567 def check_context (self , tar , filter , * , check_flag = True ):
35353568 """Extracts `tar` to `self.destdir` and allows checking the result
@@ -3803,35 +3836,6 @@ def test_parent_symlink2(self):
38033836 # Test interplaying symlinks
38043837 # Inspired by 'dirsymlink2b' in jwilk/traversal-archives
38053838
3806- # Posix and Windows have different pathname resolution:
3807- # either symlink or a '..' component resolve first.
3808- # Let's see which we are on.
3809- if os_helper .can_symlink ():
3810- testpath = os .path .join (TEMPDIR , 'resolution_test' )
3811- os .mkdir (testpath )
3812-
3813- # testpath/current links to `.` which is all of:
3814- # - `testpath`
3815- # - `testpath/current`
3816- # - `testpath/current/current`
3817- # - etc.
3818- os .symlink ('.' , os .path .join (testpath , 'current' ))
3819-
3820- # we'll test where `testpath/current/../file` ends up
3821- with open (os .path .join (testpath , 'current' , '..' , 'file' ), 'w' ):
3822- pass
3823-
3824- if os .path .exists (os .path .join (testpath , 'file' )):
3825- # Windows collapses 'current\..' to '.' first, leaving
3826- # 'testpath\file'
3827- dotdot_resolves_early = True
3828- elif os .path .exists (os .path .join (testpath , '..' , 'file' )):
3829- # Posix resolves 'current' to '.' first, leaving
3830- # 'testpath/../file'
3831- dotdot_resolves_early = False
3832- else :
3833- raise AssertionError ('Could not determine link resolution' )
3834-
38353839 with ArchiveMaker () as arc :
38363840
38373841 # `current` links to `.` which is both the destination directory
@@ -3867,7 +3871,7 @@ def test_parent_symlink2(self):
38673871
38683872 with self .check_context (arc .open (), 'data' ):
38693873 if os_helper .can_symlink ():
3870- if dotdot_resolves_early :
3874+ if self . dotdot_resolves_early :
38713875 # Fail when extracting a file outside destination
38723876 self .expect_exception (
38733877 tarfile .OutsideDestinationError ,
0 commit comments