|
| 1 | +import errno |
1 | 2 | import sys
|
2 | 3 | import os
|
3 | 4 | import io
|
@@ -3659,14 +3660,26 @@ def test_modes(self):
|
3659 | 3660 | tmp_filename = os.path.join(TEMPDIR, "tmp.file")
|
3660 | 3661 | with open(tmp_filename, 'w'):
|
3661 | 3662 | 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) |
3670 | 3683 |
|
3671 | 3684 | os.mkdir(tmp_filename)
|
3672 | 3685 | new_mode = (os.stat(tmp_filename).st_mode
|
|
0 commit comments