Skip to content

Commit 26e06ad

Browse files
authored
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 608c1f3 commit 26e06ad

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

Lib/test/test_tarfile.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import errno
12
import sys
23
import os
34
import io
@@ -3823,14 +3824,26 @@ def test_modes(self):
38233824
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
38243825
with open(tmp_filename, 'w'):
38253826
pass
3826-
new_mode = (os.stat(tmp_filename).st_mode
3827-
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
3828-
os.chmod(tmp_filename, new_mode)
3829-
got_mode = os.stat(tmp_filename).st_mode
3830-
_t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
3831-
_suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
3832-
_sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
3833-
os.unlink(tmp_filename)
3827+
try:
3828+
new_mode = (os.stat(tmp_filename).st_mode
3829+
| stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
3830+
try:
3831+
os.chmod(tmp_filename, new_mode)
3832+
except OSError as exc:
3833+
if exc.errno == getattr(errno, "EFTYPE", 0):
3834+
# gh-108948: On FreeBSD, regular users cannot set
3835+
# the sticky bit.
3836+
self.skipTest("chmod() failed with EFTYPE: "
3837+
"regular users cannot set sticky bit")
3838+
else:
3839+
raise
3840+
3841+
got_mode = os.stat(tmp_filename).st_mode
3842+
_t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
3843+
_suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
3844+
_sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
3845+
finally:
3846+
os.unlink(tmp_filename)
38343847

38353848
os.mkdir(tmp_filename)
38363849
new_mode = (os.stat(tmp_filename).st_mode

0 commit comments

Comments
 (0)