8000 gh-108948: tarfile should handle sticky bit in FreeBSD by sorcio · Pull Request #108950 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
Commits
File filter
8000

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bit of polishing
  • Loading branch information
sorcio committed Sep 16, 2023
commit 5a51aabf35891b03c671c1977987df044d3068c7
12 changes: 5 additions & 7 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3061,6 +3061,8 @@ def test_keyword_only(self, mock_geteuid):


def can_chmod_set_sticky():
Copy link
Member

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().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"""Can chmod set the sticky bit on a file?"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain in the docstring that it returns False if chmod() doesn't fail but ignores the sticky bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


def can_chmod_set_sticky_inner():
< 8000 span class='blob-code-inner blob-code-marker ' data-code-marker=" "> if not os_helper.can_chmod():
return False
Expand All @@ -3085,27 +3087,23 @@ def can_chmod_set_sticky_inner():

@os_helper.skip_unless_working_chmod
class FileModesTest(unittest.TestCase):
@unittest.skipUnless(hasattr(errno, "EFTYPE"), "errno.EFTYPE required")
@unittest.skipUnless(hasattr(errno, "EFTYPE"), "requires errno.EFTYPE")
def test_extract_chmod_eftype(self):
# Extracting a file as non-root should skip the sticky bit (gh-108948)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Extracting a file as non-root should skip the sticky bit (gh-108948)
# gh-108948: Extracting a file as non-root should skip the sticky bit

# even on platforms where chmod fails with EFTYPE (i.e. FreeBSD). But
# we need to take care that any other error is preserved.
mode = "-rwxrwxrwt"
expected_mode = mode if can_chmod_set_sticky() else "-rwxrwxrwx"
with ArchiveMaker() as arc:
arc.add("sticky1", mode=mode)
arc.add("sticky2", mode=mode)
tar = arc.open(errorlevel=2)
DIR = os.path.join(TEMPDIR, "chmod")
os.mkdir(DIR)
self.addCleanup(os_helper.rmtree, DIR)
with tar:
with arc.open(errorlevel=2) as tar:
# this should not raise:
tar.extract("sticky1", DIR, filter="fully_trusted")
got_mode = stat.filemode(os.stat(os.path.join(DIR, "sticky1")).st_mode)
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:
Expand Down
0