Skip to content

Commit

Permalink
fix: handle archives without info/files
Browse files Browse the repository at this point in the history
Apparently it's possible for an archive to have only info/paths.json.
  • Loading branch information
adam-azarchs committed Nov 14, 2024
1 parent e9b50c1 commit 7399b32
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion rules/conda_package_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ load(
"use_netrc",
)

def _is_empty(ctx):
"""Returns true if the metadata indicates that this is an empty archive."""
files_list = ctx.path("info/files")
if files_list.exists:
return not ctx.read(files_list).strip()
paths_json = ctx.path("info/paths.json")
if not paths_json.exists:
fail("Archive contained neither info/files nor info/paths.json")
return not json.decode(ctx.read(paths_json)).get("paths")

def _conda_package_repository_impl(ctx):
# Get this path here, because it might trigger a restart of the fetch,
# which would be better to have happen before we download anything.
Expand Down Expand Up @@ -53,7 +63,7 @@ def _conda_package_repository_impl(ctx):
ctx.delete("info-{}.tar.zst".format(ctx.attr.dist_name))

# Do not attempt to untar empty archives.
if ctx.read("info/files").strip():
if not _is_empty(ctx):
ctx.extract("pkg-{}.tar.zst".format(ctx.attr.dist_name))
ctx.delete("pkg-{}.tar.zst".format(ctx.attr.dist_name))
else:
Expand Down

0 comments on commit 7399b32

Please sign in to comment.