Skip to content

Commit ae62b3a

Browse files
encukoumcepl
authored andcommitted
pythongh-102950: Adjust tarfile filter tests for systems that don't set the sticky bit (pythonGH-103831)
Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is enough. Backport of c8c3956
1 parent 688286c commit ae62b3a

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

Lib/test/test_tarfile.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,23 +3513,43 @@ def test_modes(self):
35133513
arc.add('exec_group_other', mode='?rw-rwxrwx')
35143514
arc.add('read_group_only', mode='?---r-----')
35153515
arc.add('no_bits', mode='?---------')
3516-
arc.add('dir/', mode='?---rwsrwt', type=tarfile.DIRTYPE)
3516+
arc.add('dir/', mode='?---rwsrwt')
3517+
3518+
# On some systems, setting the sticky bit is a no-op.
3519+
# Check if that's the case.
3520+
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
3521+
with open(tmp_filename, 'w'):
3522+
pass
3523+
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3524+
have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3525+
os.unlink(tmp_filename)
3526+
3527+
os.mkdir(tmp_filename)
3528+
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3529+
have_sticky_dirs = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3530+
os.rmdir(tmp_filename)
35173531

35183532
with self.check_context(arc.open(), 'fully_trusted'):
3519-
self.expect_file('all_bits', mode='?rwsrwsrwt')
3533+
if have_sticky_files:
3534+
self.expect_file('all_bits', mode='?rwsrwsrwt')
3535+
else:
3536+
self.expect_file('all_bits', mode='?rwsrwsrwx')
35203537
self.expect_file('perm_bits', mode='?rwxrwxrwx')
35213538
self.expect_file('exec_group_other', mode='?rw-rwxrwx')
35223539
self.expect_file('read_group_only', mode='?---r-----')
35233540
self.expect_file('no_bits', mode='?---------')
3524-
self.expect_file('dir', type=tarfile.DIRTYPE, mode='?---rwsrwt')
3541+
if have_sticky_dirs:
3542+
self.expect_file('dir/', mode='?---rwsrwt')
3543+
else:
3544+
self.expect_file('dir/', mode='?---rwsrwx')
35253545

35263546
with self.check_context(arc.open(), 'tar'):
35273547
self.expect_file('all_bits', mode='?rwxr-xr-x')
35283548
self.expect_file('perm_bits', mode='?rwxr-xr-x')
35293549
self.expect_file('exec_group_other', mode='?rw-r-xr-x')
35303550
self.expect_file('read_group_only', mode='?---r-----')
35313551
self.expect_file('no_bits', mode='?---------')
3532-
self.expect_file('dir/', type=tarfile.DIRTYPE, mode='?---r-xr-x')
3552+
self.expect_file('dir/', mode='?---r-xr-x')
35333553

35343554
with self.check_context(arc.open(), 'data'):
35353555
normal_dir_mode = stat.filemode(stat.S_IMODE(
@@ -3539,7 +3559,7 @@ def test_modes(self):
35393559
self.expect_file('exec_group_other', mode='?rw-r--r--')
35403560
self.expect_file('read_group_only', mode='?rw-r-----')
35413561
self.expect_file('no_bits', mode='?rw-------')
3542-
self.expect_file('dir/', type=tarfile.DIRTYPE, mode=normal_dir_mode)
3562+
self.expect_file('dir/', mode=normal_dir_mode)
35433563

35443564
def test_pipe(self):
35453565
# Test handling of a special file

0 commit comments

Comments
 (0)