|
| 1 | +import errno |
1 | 2 | import sys
|
2 | 3 | import os
|
3 | 4 | import io
|
@@ -3699,14 +3700,26 @@ def test_modes(self):
|
3699 | 3700 | tmp_filename = os.path.join(TEMPDIR, "tmp.file")
|
3700 | 3701 | with open(tmp_filename, 'w'):
|
3701 | 3702 | pass
|
3702 |
| - new_mode = (os.stat(tmp_filename).st_mode |
3703 |
| - | stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID) |
3704 |
| - os.chmod(tmp_filename, new_mode) |
3705 |
| - got_mode = os.stat(tmp_filename).st_mode |
3706 |
| - _t_file = 't' if (got_mode & stat.S_ISVTX) else 'x' |
3707 |
| - _suid_file = 's' if (got_mode & stat.S_ISUID) else 'x' |
3708 |
| - _sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x' |
3709 |
| - os.unlink(tmp_filename) |
| 3703 | + try: |
| 3704 | + new_mode = (os.stat(tmp_filename).st_mode |
| 3705 | + | stat.S_ISVTX | stat.S_ISGID | stat.S_ISUID) |
| 3706 | + try: |
| 3707 | + os.chmod(tmp_filename, new_mode) |
| 3708 | + except OSError as exc: |
| 3709 | + if exc.errno == getattr(errno, "EFTYPE", 0): |
| 3710 | + # gh-108948: On FreeBSD, regular users cannot set |
| 3711 | + # the sticky bit. |
| 3712 | + self.skipTest("chmod() failed with EFTYPE: " |
| 3713 | + "regular users cannot set sticky bit") |
| 3714 | + else: |
| 3715 | + raise |
| 3716 | + |
| 3717 | + got_mode = os.stat(tmp_filename).st_mode |
| 3718 | + _t_file = 't' if (got_mode & stat.S_ISVTX) else 'x' |
| 3719 | + _suid_file = 's' if (got_mode & stat.S_ISUID) else 'x' |
| 3720 | + _sgid_file = 's' if (got_mode & stat.S_ISGID) else 'x' |
| 3721 | + finally: |
| 3722 | + os.unlink(tmp_filename) |
3710 | 3723 |
|
3711 | 3724 | os.mkdir(tmp_filename)
|
3712 | 3725 | new_mode = (os.stat(tmp_filename).st_mode
|
|
0 commit comments