Skip to content

Commit

Permalink
FIXUP: Handle tarballs with ./ prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
apyrgio committed Mar 10, 2025
1 parent 094d876 commit bb66e9a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions dev_scripts/repro-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,22 @@ def oci_normalize_path(path):


def oci_get_file_from_tarball(tar: tarfile.TarFile, path: str) -> dict:
return
"""Get file from an OCI tarball.
If the filename cannot be found, search again by prefixing it with "./", since we
have encountered path names in OCI tarballs prefixed with "./".
"""
try:
return tar.extractfile(path).read().decode()
except KeyError:
if not path.startswith("./") and not path.startswith("/"):
path = "./" + path
try:
return tar.extractfile(path).read().decode()
except KeyError:
# Do not raise here, so that we can raise the original exception below.
pass
raise


def oci_parse_manifest(tar: tarfile.TarFile, path: str, platform: dict | None) -> dict:
Expand All @@ -231,7 +246,7 @@ def oci_parse_manifest(tar: tarfile.TarFile, path: str, platform: dict | None) -
carry it from the previous manifest and include in the info here.
"""
path = oci_normalize_path(path)
contents = tar.extractfile(path).read().decode()
contents = oci_get_file_from_tarball(tar, path)
digest = "sha256:" + hashlib.sha256(contents.encode()).hexdigest()
contents_dict = json.loads(contents)
media_type = get_key(contents_dict, "mediaType")
Expand Down

0 comments on commit bb66e9a

Please sign in to comment.