|
| 1 | +import errno |
1 | 2 | import sys
|
2 | 3 | import os
|
3 | 4 | import io
|
@@ -3823,14 +3824,26 @@ def test_modes(self):
|
3823 | 3824 | tmp_filename = os.path.join(TEMPDIR, "tmp.file")
|
3824 | 3825 | with open(tmp_filename, 'w'):
|
3825 | 3826 | 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) |
3834 | 3847 |
|
3835 | 3848 | os.mkdir(tmp_filename)
|
3836 | 3849 | new_mode = (os.stat(tmp_filename).st_mode
|
|
0 commit comments