Skip to content

Commit 71a615d

Browse files
committed
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. (cherry picked from commit 26e06ad)
1 parent 4a0c118 commit 71a615d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Lib/test/test_tarfile.py

Lines changed: 16 additions & 3 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
@@ -3791,9 +3792,21 @@ def test_modes(self):
37913792
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
37923793
with open(tmp_filename, 'w'):
37933794
pass
3794-
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3795-
have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3796-
os.unlink(tmp_filename)
3795+
try:
3796+
try:
3797+
os.chmod(tmp_filename,
3798+
os.stat(tmp_filename).st_mode | stat.S_ISVTX)
3799+
except OSError as exc:
3800+
if exc.errno == getattr(errno, "EFTYPE", 0):
3801+
# gh-108948: On FreeBSD, regular users cannot set
3802+
# the sticky bit.
3803+
self.skipTest("chmod() failed with EFTYPE: "
3804+
"regular users cannot set sticky bit")
3805+
else:
3806+
raise
3807+
have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
3808+
finally:
3809+
os.unlink(tmp_filename)
37973810

37983811
os.mkdir(tmp_filename)
37993812
os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)

0 commit comments

Comments
 (0)