@@ -95,6 +95,15 @@ def is_within_directory(directory, target):
95
95
return prefix == abs_directory
96
96
97
97
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
+
98
107
def unzip_file (filename , location , flatten = True ):
99
108
# type: (str, str, bool) -> None
100
109
"""
@@ -140,9 +149,7 @@ def unzip_file(filename, location, flatten=True):
140
149
# if mode and regular file and any execute permissions for
141
150
# user/group/world?
142
151
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 )
146
153
finally :
147
154
zipfp .close ()
148
155
@@ -225,9 +232,7 @@ def untar_file(filename, location):
225
232
tar .utime (member , path ) # type: ignore
226
233
# member have any execute permissions for user/group/world?
227
234
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 )
231
236
finally :
232
237
tar .close ()
233
238
0 commit comments