summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-21 22:59:08 (GMT)
committerGitHub <noreply@github.com>2023-09-21 22:59:08 (GMT)
commit26e06ad617bb416201c769fea91cd33d544c6a1c (patch)
treee78c6f4b38a8cd7a24fb1bf6ffafbd9957aac207 /Lib/test/test_tarfile.py
parent608c1f3083ea1e06d383ef1a9878a9758903de4b (diff)
downloadcpython-26e06ad617bb416201c769fea91cd33d544c6a1c.zip
cpython-26e06ad617bb416201c769fea91cd33d544c6a1c.tar.gz
cpython-26e06ad617bb416201c769fea91cd33d544c6a1c.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r--Lib/test/test_tarfile.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 9a39dd4..cc26da0 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -1,3 +1,4 @@
+import errno
import sys
import os
import io
@@ -3823,14 +3824,26 @@ class TestExtractionFilters(unittest.TestCase):
tmp_filename = os.path.join(TEMPDIR, "tmp.file")
with open(tmp_filename, 'w'):
pass
- new_mode = (os.stat(tmp_filename).st_mode
- | stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
- os.chmod(tmp_filename, new_mode)
- got_mode = os.stat(tmp_filename).st_mode
- _t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
- _suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
- _sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
- os.unlink(tmp_filename)
+ try:
+ new_mode = (os.stat(tmp_filename).st_mode
+ | stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID)
+ try:
+ os.chmod(tmp_filename, new_mode)
+ except OSError as exc:
+ if exc.errno == getattr(errno, "EFTYPE", 0):
+ # gh-108948: On FreeBSD, regular users cannot set
+ # the sticky bit.
+ self.skipTest("chmod() failed with EFTYPE: "
+ "regular users cannot set sticky bit")
+ else:
+ raise
+
+ got_mode = os.stat(tmp_filename).st_mode
+ _t_file = 't' if (got_mode & stat.S_ISVTX) else 'x'
+ _suid_file = 's' if (got_mode & stat.S_ISUID) else 'x'
+ _sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x'
+ finally:
+ os.unlink(tmp_filename)
os.mkdir(tmp_filename)
new_mode = (os.stat(tmp_filename).st_mode