-
-
Couldn't load subscription status.
- Fork 33.2k
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 6 commits
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
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |||||||||
| # Imports | ||||||||||
| #--------- | ||||||||||
| from builtins import open as bltn_open | ||||||||||
| import errno | ||||||||||
| import sys | ||||||||||
| import os | ||||||||||
| import io | ||||||||||
|
|
@@ -2567,7 +2568,19 @@ def chmod(self, tarinfo, targetpath): | |||||||||
| if tarinfo.mode is None: | ||||||||||
| return | ||||||||||
| try: | ||||||||||
| os.chmod(targetpath, tarinfo.mode) | ||||||||||
| try: | ||||||||||
| os.chmod(targetpath, tarinfo.mode) | ||||||||||
| except OSError as e: | ||||||||||
| if not(hasattr(errno, "EFTYPE") and e.errno == errno.EFTYPE): | ||||||||||
|
||||||||||
| if not(hasattr(errno, "EFTYPE") and e.errno == errno.EFTYPE): | |
| if not(hasattr(errno, "EFTYPE") and e.errno == errno.EFTYPE and (tarinfo.mode & stat.S_ISVTX)): |
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.
Yes, at least on FreeBSD. The documentation is very explicit about the condition causing the error:
The effective user ID is not the super-user, the mode includes the sticky bit (S_ISVTX), and path does not refer to a directory.
I don't know of other systems with the same error, so the hasattr() check might be enough. But it might be a good idea to be defensive. It's not like it's an expensive check.
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.
Ok, no need to test for the bit in this case.
Outdated
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.
Do you mean that on other platforms chmod() silently ignores the sticky bit for non-root users? I'm not sure that I understood correctly.
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.
Yes, exactly. I will reword more clearly. I was being stingy on the number of lines to take for this comment :) Same in the similar comment in the test case. I will reword there too.
ethanfurman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
sorcio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
| except OSError as e: | |
| raise ExtractError("could not change mode") from e | |
| except OSError as exc3: | |
| raise ExtractError("could not change mode") from exc3 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| On FreeBSD, :mod:`tarfile` will not attempt to set the sticky bit on extracted files when it's not possible, matching the behavior of other platforms. | ||
|
||
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.
Please use variable names longer than 1 character: you can use exc and exc2.
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.
I'm in favor of this but let me double check: throughout the file the convention seems to be to use
except ... as e:. Is it okay to break the convention?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.
Please break the convention, it's a bad convention :-)