-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-108948: tarfile should handle sticky bit in FreeBSD #108950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
6a4be8f
50729f7
3587710
41491bb
4f6536d
fe7dfed
4009573
7b784b5
02d7c21
94efbbb
d1824c8
bd1dba7
417e31a
83c08fc
54f5548
b60ada6
5a51aab
cac6595
23a6fd5
060bcb2
5ae3e30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3057,6 +3057,32 @@ def test_keyword_only(self, mock_geteuid): | |
| tarfl.extract, filename_1, TEMPDIR, False, True) | ||
|
|
||
|
|
||
| _can_chmod_set_sticky = None | ||
|
|
||
|
|
||
| def can_chmod_set_sticky(): | ||
| def can_chmod_set_sticky_inner(): | ||
| if not os_helper.can_chmod(): | ||
| return False | ||
| filename = os_helper.TESTFN + "-chmod-sticky" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. honestly, just use "chmod-sticky", to avoid further troubles with non-ASCII filenames.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided not to do it, and instead just use TESTFN like |
||
| try: | ||
| with open(filename, "w") as f: | ||
| os.chmod(f.fileno(), 0o666) | ||
| try: | ||
| os.chmod(f.fileno(), 0o666 | stat.S_ISVTX) | ||
| except OSError: | ||
| return False | ||
| mode = os.stat(f.fileno()).st_mode | ||
| return bool(mode & stat.S_ISVTX) | ||
| finally: | ||
| os.unlink(filename) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's safer to use os_helper.unlink() here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
|
||
| global _can_chmod_set_sticky | ||
| if _can_chmod_set_sticky is None: | ||
| _can_chmod_set_sticky = can_chmod_set_sticky_inner() | ||
| return _can_chmod_set_sticky | ||
|
|
||
|
|
||
| @os_helper.skip_unless_working_chmod | ||
| class FileModesTest(unittest.TestCase): | ||
| @unittest.skipUnless(hasattr(errno, "EFTYPE"), "errno.EFTYPE required") | ||
|
|
@@ -3076,7 +3102,10 @@ def test_extract_chmod_eftype(self): | |
| # this should not raise: | ||
| tar.extract("sticky1", DIR, filter="fully_trusted") | ||
| got_mode = stat.filemode(os.stat(os.path.join(DIR, "sticky1")).st_mode) | ||
| expected_mode = "-rwxrwxrwx" if os.geteuid() != 0 else "-rwxrwxrwt" | ||
| if can_chmod_set_sticky(): | ||
| expected_mode = "-rwxrwxrwt" | ||
| else: | ||
| expected_mode = "-rwxrwxrwx" | ||
| self.assertEqual(got_mode, expected_mode) | ||
|
|
||
| # but we can create a situation where it does raise: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should move it to support.os_helper.
I suggest to rename to can_chmod_set_sticky_bit().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.