MCPcopy Index your code
hub / github.com/nodejs/node / extract_zip

Function extract_zip

tools/prepare_lief.py:14–42  ·  view source on GitHub ↗

Extract a third-party archive into dst_third_party/prefix. Typical structure inside the archive is a single top-level directory like "mbedtls- /". We extract under dst_third_party, then rename that directory to a stable name dst_third_party/prefix.

(prefix: str, zip_path: Path, dst_third_party: Path)

Source from the content-addressed store, hash-verified

12
13
14def extract_zip(prefix: str, zip_path: Path, dst_third_party: Path):
15 """Extract a third-party archive into dst_third_party/prefix.
16
17 Typical structure inside the archive is a single top-level directory like
18 "mbedtls-<ver>/". We extract under dst_third_party, then rename that
19 directory to a stable name dst_third_party/prefix.
20 """
21 ensure_dir(dst_third_party)
22 with zipfile.ZipFile(zip_path, 'r') as zf:
23 # Determine the top-level directory inside the archive
24 names = zf.namelist()
25 top_candidates = {n.split('/', 1)[0] for n in names if '/' in n}
26 top_dir = next((n for n in sorted(top_candidates) if n.startswith(f"{prefix}-")), None)
27 if top_dir is None: # There is no versioned top-level dir, create one
28 top_dir = prefix
29 extract_parent_dir = dst_third_party / prefix
30 if not extract_parent_dir.exists():
31 extract_parent_dir.mkdir()
32 else:
33 extract_parent_dir = dst_third_party
34 print(f"Extracting {zip_path} -> {extract_parent_dir} (top_dir: {top_dir})")
35 zf.extractall(extract_parent_dir)
36
37 extracted_dir = dst_third_party / top_dir
38 target_dir = dst_third_party / prefix
39 if extracted_dir.exists() and extracted_dir != target_dir:
40 if target_dir.exists():
41 shutil.rmtree(target_dir)
42 extracted_dir.rename(target_dir)
43
44def find_single_subdir(root: Path) -> Path:
45 entries = [p for p in root.iterdir() if p.is_dir()]

Callers 1

mainFunction · 0.85

Calls 8

ensure_dirFunction · 0.85
sortedFunction · 0.85
nextFunction · 0.50
printFunction · 0.50
splitMethod · 0.45
existsMethod · 0.45
mkdirMethod · 0.45
renameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…