Skip to content

Commit ebd331f

Browse files
authored
Merge pull request #8375 from deveshks/use-bitwise-and
Update mechanism to set permissions for files with execute permissions while extracting sdists.
2 parents dd3672f + a8e20e3 commit ebd331f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

news/5F187A50-7217-4F88-8902-548C9F534E55.trivial

Whitespace-only changes.

src/pip/_internal/utils/unpacking.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ def is_within_directory(directory, target):
9595
return prefix == abs_directory
9696

9797

98+
def set_extracted_file_to_default_mode_plus_executable(path):
99+
# type: (Union[str, Text]) -> None
100+
"""
101+
Make file present at path have execute for user/group/world
102+
(chmod +x) is no-op on windows per python docs
103+
"""
104+
os.chmod(path, (0o777 & ~current_umask() | 0o111))
105+
106+
98107
def unzip_file(filename, location, flatten=True):
99108
# type: (str, str, bool) -> None
100109
"""
@@ -140,9 +149,7 @@ def unzip_file(filename, location, flatten=True):
140149
# if mode and regular file and any execute permissions for
141150
# user/group/world?
142151
if mode and stat.S_ISREG(mode) and mode & 0o111:
143-
# make dest file have execute for user/group/world
144-
# (chmod +x) no-op on windows per python docs
145-
os.chmod(fn, (0o777 - current_umask() | 0o111))
152+
set_extracted_file_to_default_mode_plus_executable(fn)
146153
finally:
147154
zipfp.close()
148155

@@ -225,9 +232,7 @@ def untar_file(filename, location):
225232
tar.utime(member, path) # type: ignore
226233
# member have any execute permissions for user/group/world?
227234
if member.mode & 0o111:
228-
# make dest file have execute for user/group/world
229-
# no-op on windows per python docs
230-
os.chmod(path, (0o777 - current_umask() | 0o111))
235+
set_extracted_file_to_default_mode_plus_executable(path)
231236
finally:
232237
tar.close()
233238

0 commit comments

Comments
 (0)