Skip to content

Commit ee503ad

Browse files
committed
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 3fc4d5e commit ee503ad

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
@@ -3560,23 +3560,43 @@ def test_modes(self):
35603560
arc.add('exec_group_other', mode='?rw-rwxrwx')
35613561
arc.add('read_group_only', mode='?---r-----')
35623562
arc.add('no_bits', mode='?---------')
3563-
arc.add('dir/', mode='?---rwsrwt', type=tarfile.DIRTYPE)
3563+
arc.add('dir/', mode='?---rwsrwt')
3564+
3565+
# On some systems, setting the sticky bit is a no-op.
3566+
# Check if that's the case.
3567+
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
3568+
with open(tmp_filename, 'w'):
3569+
pass
3570+
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3571+
have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3572+
os.unlink(tmp_filename)
3573+
3574+
os.mkdir(tmp_filename)
3575+
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3576+
have_sticky_dirs = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3577+
os.rmdir(tmp_filename)
35643578

35653579
with self.check_context(arc.open(), 'fully_trusted'):
3566-
self.expect_file('all_bits', mode='?rwsrwsrwt')
3580+
if have_sticky_files:
3581+
self.expect_file('all_bits', mode='?rwsrwsrwt')
3582+
else:
3583+
self.expect_file('all_bits', mode='?rwsrwsrwx')
35673584
self.expect_file('perm_bits', mode='?rwxrwxrwx')
35683585
self.expect_file('exec_group_other', mode='?rw-rwxrwx')
35693586
self.expect_file('read_group_only', mode='?---r-----')
35703587
self.expect_file('no_bits', mode='?---------')
3571-
self.expect_file('dir', type=tarfile.DIRTYPE, mode='?---rwsrwt')
3588+
if have_sticky_dirs:
3589+
self.expect_file('dir/', mode='?---rwsrwt')
3590+
else:
3591+
self.expect_file('dir/', mode='?---rwsrwx')
35723592

35733593
with self.check_context(arc.open(), 'tar'):
35743594
self.expect_file('all_bits', mode='?rwxr-xr-x')
35753595
self.expect_file('perm_bits', mode='?rwxr-xr-x')
35763596
self.expect_file('exec_group_other', mode='?rw-r-xr-x')
35773597
self.expect_file('read_group_only', mode='?---r-----')
35783598
self.expect_file('no_bits', mode='?---------')
3579-
self.expect_file('dir/', type=tarfile.DIRTYPE, mode='?---r-xr-x')
3599+
self.expect_file('dir/', mode='?---r-xr-x')
35803600

35813601
with self.check_context(arc.open(), 'data'):
35823602
normal_dir_mode = stat.filemode(stat.S_IMODE(
@@ -3586,7 +3606,7 @@ def test_modes(self):
35863606
self.expect_file('exec_group_other', mode='?rw-r--r--')
35873607
self.expect_file('read_group_only', mode='?rw-r-----')
35883608
self.expect_file('no_bits', mode='?rw-------')
3589-
self.expect_file('dir/', type=tarfile.DIRTYPE, mode=normal_dir_mode)
3609+
self.expect_file('dir/', mode=normal_dir_mode)
35903610

35913611
def test_pipe(self):
35923612
# Test handling of a special file

0 commit comments

Comments
 (0)