From bddad95266e652cfb41b14a83d885a0913e3f90c Mon Sep 17 00:00:00 2001 From: lotherk Date: Mon, 23 Nov 2026 15:33:12 +0000 Subject: [PATCH] pkg-binaries, userland: the 935 MB download survives a failed run make_repo did rm -rf on build/packages/ARCH/All, the directory tools/pkg-binaries.sh downloads the NetBSD project's binary packages into: every release deleted the download and fetched it again, four times on the MacBook on 2026-11-23, 20 minutes each. The manifest and the key are now written before the first download rather than after the last, and make_repo clears only what the manifest does not name. Verified: a directory with a.tgz, b.tgz (in the manifest) and mine.tgz (not) keeps the first two and loses the third; dash -n on both scripts. --- tools/pkg-binaries.sh | 16 +++++++++++++++- tools/userland.sh | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/pkg-binaries.sh b/tools/pkg-binaries.sh index 6f6407ebf9..7c8ca6bdd6 100755 --- a/tools/pkg-binaries.sh +++ b/tools/pkg-binaries.sh @@ -195,9 +195,23 @@ echo "pkg-binaries: $ARCH $BRANCH: $(wc -l < "$tmp/pkgs" | tr -d ' ') packages, [ "$CMD" = fetch ] || exit 0 +# The manifest and the key are written before the first download, not after +# the last: a run that is stopped or fails partway used to leave neither, so +# the next run could not recognise the archives that were already here and +# fetched all 935 MB again (measured 2026-11-23 on the MacBook, four runs). +# A file of the wrong size is fetched again below, so an early manifest is +# safe. +: > "$tmp/files" +while read -r p; do + file=$(awk -F'\t' -v p="$p" '$1 == p { print $3 }' "$tmp/index") + size=$(awk -F'\t' -v p="$p" '$1 == p { print $2 }' "$tmp/index") + echo "$file $size" >> "$tmp/files" +done < "$tmp/pkgs" +cp "$tmp/files" "$OUT/.fetch-files" +printf '%s\n' "$fetchkey" > "$OUT/.fetch-key" + fail=0 stale= -: > "$tmp/files" while read -r p; do file=$(awk -F'\t' -v p="$p" '$1 == p { print $3 }' "$tmp/index") size=$(awk -F'\t' -v p="$p" '$1 == p { print $2 }' "$tmp/index") diff --git a/tools/userland.sh b/tools/userland.sh index 9778911006..63a9a3fdaa 100755 --- a/tools/userland.sh +++ b/tools/userland.sh @@ -252,8 +252,23 @@ make_repo() repo=$("$TOP/tools/pkglist.sh" repo) [ -n "$repo" ] || return 0 out=$TOP/build/packages/$ARCH/All - rm -rf "$out" + # This directory also holds the NetBSD project's binary packages + # (tools/pkg-binaries.sh), 935 MB that a run must not throw away: this used + # to be an `rm -rf $out', so every release deleted the download and fetched + # it again (measured 2026-11-23 on the MacBook, four runs of 20 minutes). + # What is cleared is the repository's own set from an earlier run, and + # .fetch-files says which files are not it. mkdir -p "$out" + if [ -f "$out/.fetch-files" ]; then + for f in "$out"/*.tgz; do + [ -f "$f" ] || continue + b=${f##*/} + awk -v b="$b" '$1 == b { found = 1 } END { exit !found }' \ + "$out/.fetch-files" || rm -f "$f" + done + else + rm -f "$out"/*.tgz + fi missing= # The run-time closure. A package's +CONTENTS names its own run-time # dependencies as "@pkgdep name>=version", and those can depend again: