Skip to content

Commit 7ab6520

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 5a5b9b9 commit 7ab6520

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
@@ -3659,14 +3660,26 @@ def test_modes(self):
36593660
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
36603661
with open(tmp_filename, 'w'):
36613662
pass
3662-
new_mode = (os.stat(tmp_filename).st_mode
3663-
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
3664-
os.chmod(tmp_filename, new_mode)
3665-
got_mode = os.stat(tmp_filename).st_mode
3666-
_t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
3667-
_suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
3668-
_sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
3669-
os.unlink(tmp_filename)
3663+
try:
3664+
new_mode = (os.stat(tmp_filename).st_mode
3665+
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
3666+
try:
3667+
os.chmod(tmp_filename, new_mode)
3668+
except OSError as exc:
3669+
if exc.errno == getattr(errno, "EFTYPE", 0):
3670+
# gh-108948: On FreeBSD, regular users cannot set
3671+
# the sticky bit.
3672+
self.skipTest("chmod() failed with EFTYPE: "
3673+
"regular users cannot set sticky bit")
3674+
else:
3675+
raise
3676+
3677+
got_mode = os.stat(tmp_filename).st_mode
3678+
_t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
3679+
_suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
3680+
_sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
3681+
finally:
3682+
os.unlink(tmp_filename)
36703683

36713684
os.mkdir(tmp_filename)
36723685
new_mode = (os.stat(tmp_filename).st_mode

0 commit comments

Comments
 (0)