Skip to content
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

Fix generated file mode to use bitwise AND #8166

Merged
merged 4 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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
1 change: 1 addition & 0 deletions news/8164.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix metadata permission issues when umask has the executable bit set.
2 changes: 1 addition & 1 deletion src/pip/_internal/operations/install/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def is_entrypoint_wrapper(name):
if msg is not None:
logger.warning(msg)

generated_file_mode = 0o666 - current_umask()
generated_file_mode = 0o666 & ~current_umask()

@contextlib.contextmanager
def _generate_file(path, **kwargs):
Expand Down
31 changes: 26 additions & 5 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ def assert_permission(self, path, mode):
target_mode = os.stat(path).st_mode & 0o777
assert (target_mode & mode) == mode, oct(target_mode)
deveshks marked this conversation as resolved.
Show resolved Hide resolved

def assert_installed(self):
def assert_installed(self, expected_permission):
# lib
assert os.path.isdir(
os.path.join(self.scheme.purelib, 'sample'))
# dist-info
metadata = os.path.join(self.dest_dist_info, 'METADATA')
self.assert_permission(metadata, 0o644)
self.assert_permission(metadata, expected_permission)
record = os.path.join(self.dest_dist_info, 'RECORD')
self.assert_permission(record, 0o644)
self.assert_permission(record, expected_permission)
# data files
data_file = os.path.join(self.scheme.data, 'my_data', 'data_file')
assert os.path.isfile(data_file)
Expand All @@ -268,7 +268,28 @@ def test_std_install(self, data, tmpdir):
scheme=self.scheme,
req_description=str(self.req),
)
self.assert_installed()
self.assert_installed(0o644)

@pytest.mark.parametrize("user_mask, expected_permission", [
(0o27, 0o640)
])
def test_std_install_with_custom_umask(self, data, tmpdir,
user_mask, expected_permission):
"""Test that the files created after install honor the permissions
set when the user sets a custom umask"""

prev_umask = os.umask(user_mask)
try:
self.prep(data, tmpdir)
wheel.install_wheel(
self.name,
self.wheelpath,
scheme=self.scheme,
req_description=str(self.req),
)
self.assert_installed(expected_permission)
finally:
os.umask(prev_umask)

def test_std_install_with_direct_url(self, data, tmpdir):
"""Test that install_wheel creates direct_url.json metadata when
Expand Down Expand Up @@ -340,7 +361,7 @@ def test_dist_info_contains_empty_dir(self, data, tmpdir):
req_description=str(self.req),
_temp_dir_for_testing=self.src,
)
self.assert_installed()
self.assert_installed(0o644)
assert not os.path.isdir(
os.path.join(self.dest_dist_info, 'empty_dir'))

Expand Down