Skip to content
Merged
2 changes: 1 addition & 1 deletion news/11012.feature.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Network cache file permissions will inherit the permissions of the cache's directory with the exception of owner read/write permissions which will always be set. This feature enables sharing a cache in a multi-user environment.
Network cache file permissions will inherit the read/write permissions of the cache's directory with the exception of owner read/write permissions which will always be set. This feature enables sharing a cache in a multi-user environment.
4 changes: 3 additions & 1 deletion src/pip/_internal/network/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def _write(self, path: str, data: bytes) -> None:
with adjacent_tmp_file(path) as f:
f.write(data)

os.chmod(f.name, os.stat(self.directory).st_mode & 0o777 | 0o600)
# `& 0o666` selects the read/write permissions of the directory.
# `| 0o600` sets owner read/write permissions.
os.chmod(f.name, os.stat(self.directory).st_mode & 0o666 | 0o600)
replace(f.name, path)

def set(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_network_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_cache_hashes_are_same(self, cache_tmpdir: Path) -> None:

@pytest.mark.skipif("sys.platform == 'win32'")
@pytest.mark.parametrize(
"perms, expected_perms", [(0o300, 0o700), (0o700, 0o700), (0o777, 0o777)]
"perms, expected_perms", [(0o300, 0o600), (0o700, 0o600), (0o777, 0o666)]
)
def test_cache_inherits_perms(
self, cache_tmpdir: Path, perms: int, expected_perms: int
Expand Down
Loading