]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-108948: Skip test_tarfile.test_modes() on EFTYPE error (#109697) (#109698)
authorVictor Stinner <vstinner@python.org>
Mon, 2 Oct 2023 15:16:25 +0000 (17:16 +0200)
committerGitHub <noreply@github.com>
Mon, 2 Oct 2023 15:16:25 +0000 (17:16 +0200)
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 26e06ad617bb416201c769fea91cd33d544c6a1c)

Lib/test/test_tarfile.py

index 5d9714eb287e10630af5ff0a64ab96151bf31c92..c5fc76dc0207d4f761365e43738c26b8cdb4df36 100644 (file)
@@ -1,3 +1,4 @@
+import errno
 import sys
 import os
 import io
@@ -3798,9 +3799,21 @@ class TestExtractionFilters(unittest.TestCase):
         tmp_filename = os.path.join(TEMPDIR, "tmp.file")
         with open(tmp_filename, 'w'):
             pass
-        os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)
-        have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
-        os.unlink(tmp_filename)
+        try:
+            try:
+                os.chmod(tmp_filename,
+                         os.stat(tmp_filename).st_mode | stat.S_ISVTX)
+            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
+            have_sticky_files = (os.stat(tmp_filename).st_mode & stat.S_ISVTX)
+        finally:
+            os.unlink(tmp_filename)
 
         os.mkdir(tmp_filename)
         os.chmod(tmp_filename, os.stat(tmp_filename).st_mode | stat.S_ISVTX)