Skip to content

Commit 15a108e

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 1949dc2 commit 15a108e

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
@@ -3470,23 +3470,43 @@ def test_modes(self):
34703470
arc.add('exec_group_other', mode='?rw-rwxrwx')
34713471
arc.add('read_group_only', mode='?---r-----')
34723472
arc.add('no_bits', mode='?---------')
3473-
arc.add('dir/', mode='?---rwsrwt', type=tarfile.DIRTYPE)
3473+
arc.add('dir/', mode='?---rwsrwt')
3474+
3475+
# On some systems, setting the sticky bit is a no-op.
3476+
# Check if that's the case.
3477+
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
3478+
with open(tmp_filename, 'w'):
3479+
pass
3480+
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3481+
have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3482+
os.unlink(tmp_filename)
3483+
3484+
os.mkdir(tmp_filename)
3485+
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3486+
have_sticky_dirs = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3487+
os.rmdir(tmp_filename)
34743488

34753489
with self.check_context(arc.open(), 'fully_trusted'):
3476-
self.expect_file('all_bits', mode='?rwsrwsrwt')
3490+
if have_sticky_files:
3491+
self.expect_file('all_bits', mode='?rwsrwsrwt')
3492+
else:
3493+
self.expect_file('all_bits', mode='?rwsrwsrwx')
34773494
self.expect_file('perm_bits', mode='?rwxrwxrwx')
34783495
self.expect_file('exec_group_other', mode='?rw-rwxrwx')
34793496
self.expect_file('read_group_only', mode='?---r-----')
34803497
self.expect_file('no_bits', mode='?---------')
3481-
self.expect_file('dir', type=tarfile.DIRTYPE, mode='?---rwsrwt')
3498+
if have_sticky_dirs:
3499+
self.expect_file('dir/', mode='?---rwsrwt')
3500+
else:
3501+
self.expect_file('dir/', mode='?---rwsrwx')
34823502

34833503
with self.check_context(arc.open(), 'tar'):
34843504
self.expect_file('all_bits', mode='?rwxr-xr-x')
34853505
self.expect_file('perm_bits', mode='?rwxr-xr-x')
34863506
self.expect_file('exec_group_other', mode='?rw-r-xr-x')
34873507
self.expect_file('read_group_only', mode='?---r-----')
34883508
self.expect_file('no_bits', mode='?---------')
3489-
self.expect_file('dir/', type=tarfile.DIRTYPE, mode='?---r-xr-x')
3509+
self.expect_file('dir/', mode='?---r-xr-x')
34903510

34913511
with self.check_context(arc.open(), 'data'):
34923512
normal_dir_mode = stat.filemode(stat.S_IMODE(
@@ -3496,7 +3516,7 @@ def test_modes(self):
34963516
self.expect_file('exec_group_other', mode='?rw-r--r--')
34973517
self.expect_file('read_group_only', mode='?rw-r-----')
34983518
self.expect_file('no_bits', mode='?rw-------')
3499-
self.expect_file('dir/', type=tarfile.DIRTYPE, mode=normal_dir_mode)
3519+
self.expect_file('dir/', mode=normal_dir_mode)
35003520

35013521
def test_pipe(self):
35023522
# Test handling of a special file

0 commit comments

Comments
 (0)