MCPcopy Create free account
hub / github.com/numpy/numpy / extract_tarfile_to

Function extract_tarfile_to

tools/openblas_support.py:214–235  ·  view source on GitHub ↗

Extract TarFile contents under archive_path/ to target_path/

(tarfileobj, target_path, archive_path)

Source from the content-addressed store, hash-verified

212
213
214def extract_tarfile_to(tarfileobj, target_path, archive_path):
215 """Extract TarFile contents under archive_path/ to target_path/"""
216
217 target_path = os.path.abspath(target_path)
218
219 def get_members():
220 for member in tarfileobj.getmembers():
221 if archive_path:
222 norm_path = os.path.normpath(member.name)
223 if norm_path.startswith(archive_path + os.path.sep):
224 member.name = norm_path[len(archive_path)+1:]
225 else:
226 continue
227
228 dst_path = os.path.abspath(os.path.join(target_path, member.name))
229 if os.path.commonpath([target_path, dst_path]) != target_path:
230 # Path not under target_path, probably contains ../
231 continue
232
233 yield member
234
235 tarfileobj.extractall(target_path, members=get_members())
236
237
238def make_init(dirname):

Callers 1

unpack_targzFunction · 0.85

Calls 2

get_membersFunction · 0.85
abspathMethod · 0.45

Tested by

no test coverage detected