From cc86b7f1796a02c738670bd236cfa2ac566e2760 Mon Sep 17 00:00:00 2001 From: Devesh Kumar Singh Date: Tue, 2 Jun 2020 13:54:01 +0530 Subject: [PATCH 1/3] Use bitwise AND to set file permissions --- src/pip/_internal/utils/unpacking.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/pip/_internal/utils/unpacking.py b/src/pip/_internal/utils/unpacking.py index fe71d26e355..2c54131981f 100644 --- a/src/pip/_internal/utils/unpacking.py +++ b/src/pip/_internal/utils/unpacking.py @@ -95,6 +95,15 @@ def is_within_directory(directory, target): return prefix == abs_directory +def set_file_modes(path): + # type: (Union[str, Text]) -> None + """ + Make file present at path have execute for user/group/world + (chmod +x) is no-op on windows per python docs + """ + os.chmod(path, (0o777 & ~current_umask() | 0o111)) + + def unzip_file(filename, location, flatten=True): # type: (str, str, bool) -> None """ @@ -140,9 +149,7 @@ def unzip_file(filename, location, flatten=True): # if mode and regular file and any execute permissions for # user/group/world? if mode and stat.S_ISREG(mode) and mode & 0o111: - # make dest file have execute for user/group/world - # (chmod +x) no-op on windows per python docs - os.chmod(fn, (0o777 - current_umask() | 0o111)) + set_file_modes(fn) finally: zipfp.close() @@ -225,9 +232,7 @@ def untar_file(filename, location): tar.utime(member, path) # type: ignore # member have any execute permissions for user/group/world? if member.mode & 0o111: - # make dest file have execute for user/group/world - # no-op on windows per python docs - os.chmod(path, (0o777 - current_umask() | 0o111)) + set_file_modes(path) finally: tar.close() From 20a933d8f752e819bd19232bfb50393123ca94c8 Mon Sep 17 00:00:00 2001 From: Devesh Kumar Singh Date: Tue, 2 Jun 2020 13:55:22 +0530 Subject: [PATCH 2/3] Add news entry --- news/5F187A50-7217-4F88-8902-548C9F534E55.trivial | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 news/5F187A50-7217-4F88-8902-548C9F534E55.trivial diff --git a/news/5F187A50-7217-4F88-8902-548C9F534E55.trivial b/news/5F187A50-7217-4F88-8902-548C9F534E55.trivial new file mode 100644 index 00000000000..e69de29bb2d From a8e20e36b2f75fcae8ec3f176ddc53e333923f29 Mon Sep 17 00:00:00 2001 From: Devesh Kumar Singh Date: Tue, 2 Jun 2020 15:56:38 +0530 Subject: [PATCH 3/3] Rename function --- src/pip/_internal/utils/unpacking.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pip/_internal/utils/unpacking.py b/src/pip/_internal/utils/unpacking.py index 2c54131981f..8966052d903 100644 --- a/src/pip/_internal/utils/unpacking.py +++ b/src/pip/_internal/utils/unpacking.py @@ -95,7 +95,7 @@ def is_within_directory(directory, target): return prefix == abs_directory -def set_file_modes(path): +def set_extracted_file_to_default_mode_plus_executable(path): # type: (Union[str, Text]) -> None """ Make file present at path have execute for user/group/world @@ -149,7 +149,7 @@ def unzip_file(filename, location, flatten=True): # if mode and regular file and any execute permissions for # user/group/world? if mode and stat.S_ISREG(mode) and mode & 0o111: - set_file_modes(fn) + set_extracted_file_to_default_mode_plus_executable(fn) finally: zipfp.close() @@ -232,7 +232,7 @@ def untar_file(filename, location): tar.utime(member, path) # type: ignore # member have any execute permissions for user/group/world? if member.mode & 0o111: - set_file_modes(path) + set_extracted_file_to_default_mode_plus_executable(path) finally: tar.close()