Skip to content

Commit cabcaf2

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 57b003a commit cabcaf2

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

Lib/test/test_tarfile.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -3288,23 +3288,43 @@ def test_modes(self):
32883288
arc.add('exec_group_other', mode='?rw-rwxrwx')
32893289
arc.add('read_group_only', mode='?---r-----')
32903290
arc.add('no_bits', mode='?---------')
3291-
arc.add('dir/', mode='?---rwsrwt', type=tarfile.DIRTYPE)
3291+
arc.add('dir/', mode='?---rwsrwt')
3292+
3293+
# On some systems, setting the sticky bit is a no-op.
3294+
# Check if that's the case.
3295+
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
3296+
with open(tmp_filename, 'w'):
3297+
pass
3298+
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3299+
have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3300+
os.unlink(tmp_filename)
3301+
3302+
os.mkdir(tmp_filename)
3303+
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3304+
have_sticky_dirs = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3305+
os.rmdir(tmp_filename)
32923306

32933307
with self.check_context(arc.open(), 'fully_trusted'):
3294-
self.expect_file('all_bits', mode='?rwsrwsrwt')
3308+
if have_sticky_files:
3309+
self.expect_file('all_bits', mode='?rwsrwsrwt')
3310+
else:
3311+
self.expect_file('all_bits', mode='?rwsrwsrwx')
32953312
self.expect_file('perm_bits', mode='?rwxrwxrwx')
32963313
self.expect_file('exec_group_other', mode='?rw-rwxrwx')
32973314
self.expect_file('read_group_only', mode='?---r-----')
32983315
self.expect_file('no_bits', mode='?---------')
3299-
self.expect_file('dir', type=tarfile.DIRTYPE, mode='?---rwsrwt')
3316+
if have_sticky_dirs:
3317+
self.expect_file('dir/', mode='?---rwsrwt')
3318+
else:
3319+
self.expect_file('dir/', mode='?---rwsrwx')
33003320

33013321
with self.check_context(arc.open(), 'tar'):
33023322
self.expect_file('all_bits', mode='?rwxr-xr-x')
33033323
self.expect_file('perm_bits', mode='?rwxr-xr-x')
33043324
self.expect_file('exec_group_other', mode='?rw-r-xr-x')
33053325
self.expect_file('read_group_only', mode='?---r-----')
33063326
self.expect_file('no_bits', mode='?---------')
3307-
self.expect_file('dir/', type=tarfile.DIRTYPE, mode='?---r-xr-x')
3327+
self.expect_file('dir/', mode='?---r-xr-x')
33083328

33093329
with self.check_context(arc.open(), 'data'):
33103330
normal_dir_mode = stat.filemode(stat.S_IMODE(
@@ -3314,7 +3334,7 @@ def test_modes(self):
33143334
self.expect_file('exec_group_other', mode='?rw-r--r--')
33153335
self.expect_file('read_group_only', mode='?rw-r-----')
33163336
self.expect_file('no_bits', mode='?rw-------')
3317-
self.expect_file('dir/', type=tarfile.DIRTYPE, mode=normal_dir_mode)
3337+
self.expect_file('dir/', mode=normal_dir_mode)
33183338

33193339
def test_pipe(self):
33203340
# Test handling of a special file

0 commit comments

Comments
 (0)