103def unzip_file(filename: str, location: str, flatten: bool =
True) ->
None:
105 Unzip the file (with path `filename`) to the destination `location`. All
106 files are written based on system defaults and umask (i.e. permissions are
107 not preserved), except that regular file members with any execute
108 permissions (user, group, or world) have "chmod +x" applied after being
109 written. Note that for windows, any execute changes using os.chmod are
110 no-ops per the python docs.
113 zipfp = open(filename,
"rb")
124 if not is_within_directory(location, fn):
126 "The zip file ({}) has a file ({}) trying to install "
127 "outside target directory ({})"
139 with open(fn,
"wb")
as destfp:
143 if zip_item_is_executable(info):
144 set_extracted_file_to_default_mode_plus_executable(fn)
151 Untar the file (with path `filename`) to the destination `location`.
152 All files are written based on system defaults and umask (i.e. permissions
153 are not preserved), except that regular file members with any execute
154 permissions (user, group, or world) have "chmod +x" applied after being
155 written. Note that for windows, any execute changes using os.chmod are
156 no-ops per the python docs.
169 "Cannot determine compression type for file %s",
181 if not is_within_directory(location, path):
183 "The tar file ({}) has a file ({}) trying to install "
184 "outside target directory ({})"
192 except Exception
as exc:
196 "In the tar file %s the member %s is invalid: %s",
205 except (KeyError, AttributeError)
as exc:
209 "In the tar file %s the member %s is invalid: %s",
216 assert fp
is not None
217 with open(path,
"wb")
as destfp:
224 set_extracted_file_to_default_mode_plus_executable(path)