Skip to content

Commit 6edbff9

Browse files
Inline the single-use extract helper
1 parent 181821d commit 6edbff9

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎socketsecurity/core/tools/reachability.py‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,8 @@ def download(component: _CoanaComponent, dest: pathlib.Path) -> None:
386386
f"got {received} bytes with sha256 {sha256})"
387387
)
388388

389-
def extract(tarball: pathlib.Path, dest: pathlib.Path) -> None:
390-
def regular_files_only(member: tarfile.TarInfo, path: str) -> Optional[tarfile.TarInfo]:
391-
return tarfile.data_filter(member, path) if member.isfile() or member.isdir() else None
392-
393-
with tarfile.open(tarball, "r:gz") as archive:
394-
# Without extraction filters, the checked sha256 vouches for the tarball.
395-
archive.extractall(dest, **({"filter": regular_files_only} if hasattr(tarfile, "data_filter") else {}))
389+
def regular_files_only(member: tarfile.TarInfo, path: str) -> Optional[tarfile.TarInfo]:
390+
return tarfile.data_filter(member, path) if member.isfile() or member.isdir() else None
396391

397392
if _EXACT_VERSION.fullmatch(version_spec) and (cached := lookup(version_spec)):
398393
return cached
@@ -410,7 +405,11 @@ def regular_files_only(member: tarfile.TarInfo, path: str) -> Optional[tarfile.T
410405
artifacts = request_artifacts(artifacts.version)
411406
download(artifacts.cli, tarball)
412407
extract_dir = pathlib.Path(tmp, "cli")
413-
extract(tarball, extract_dir)
408+
with tarfile.open(tarball, "r:gz") as archive:
409+
# Without extraction filters, the checked sha256 vouches for the tarball.
410+
archive.extractall(
411+
extract_dir, **({"filter": regular_files_only} if hasattr(tarfile, "data_filter") else {})
412+
)
414413
return printed_dir(
415414
run_coana_cache("install", artifacts.version, _COANA_COMPONENT, artifacts.cli.sha256, str(extract_dir))
416415
)

0 commit comments

Comments
 (0)