Skip to content

Commit 95bfff7

Browse files
vstinnerencukou
authored andcommitted
gh-108948: Skip test_tarfile.test_modes() on EFTYPE error (#109697)
On FreeBSD, regular users cannot set the sticky bit. Skip the test if chmod() fails with EFTYPE error.
1 parent e3ecd5b commit 95bfff7

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

Lib/test/test_tarfile.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import errno
12
import sys
23
import os
34
import io
@@ -3699,14 +3700,26 @@ def test_modes(self):
36993700
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
37003701
with open(tmp_filename, 'w'):
37013702
pass
3702-
new_mode = (os.stat(tmp_filename).st_mode
3703-
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
3704-
os.chmod(tmp_filename, new_mode)
3705-
got_mode = os.stat(tmp_filename).st_mode
3706-
_t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
3707-
_suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
3708-
_sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
3709-
os.unlink(tmp_filename)
3703+
try:
3704+
new_mode = (os.stat(tmp_filename).st_mode
3705+
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
3706+
try:
3707+
os.chmod(tmp_filename, new_mode)
3708+
except OSError as exc:
3709+
if exc.errno == getattr(errno, "EFTYPE", 0):
3710+
# gh-108948: On FreeBSD, regular users cannot set
3711+
# the sticky bit.
3712+
self.skipTest("chmod() failed with EFTYPE: "
3713+
"regular users cannot set sticky bit")
3714+
else:
3715+
raise
3716+
3717+
got_mode = os.stat(tmp_filename).st_mode
3718+
_t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
3719+
_suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
3720+
_sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
3721+
finally:
3722+
os.unlink(tmp_filename)
37103723

37113724
os.mkdir(tmp_filename)
37123725
new_mode = (os.stat(tmp_filename).st_mode

0 commit comments

Comments
 (0)