build: salvage only whole packages with a manifest

FreeBSD's tar lists an empty file as an empty archive, so a package
file cut off at zero bytes passed salvage_ports' check. A salvaged
package must now also hold +MANIFEST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jeremy Karst 2026-11-20 13:52:43 -05:00
parent 1addff9484
commit f31a70765a
3 changed files with 22 additions and 8 deletions

View file

@ -218,7 +218,7 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
so `build` first adds them to the set: the runtime packages tools had
copied to the stage's packages directory, if the stage belongs to the
same build (series, version and ports commit, kept in
`/var/tmp/gwbuild-ports.run`) and each is a whole archive. The
`/var/tmp/gwbuild-ports.run`) and each is a whole package archive. The
build-only dependencies are not kept and get rebuilt. A port that
fails is recorded and the step goes on with the others, then fails at the
end. Tools stops at the first failure only when its step is given an

View file

@ -172,7 +172,7 @@ build_ports()
# which the next step clears. They are added if the stage belongs to this build:
# PORTS_RUN holds the ID (series, version, ports commit) of the last ports step
# started. Packages the set has are skipped, and so is one that is not a whole
# archive (written when the host went down). The build-only dependencies in the
# package archive with its +MANIFEST (written when the host went down). The build-only dependencies in the
# step's cache are not added (they are not part of the set); the next step
# rebuilds the ones it needs.
salvage_ports()
@ -185,7 +185,9 @@ salvage_ports()
[ -f "${_pkg}" ] || continue
_entry=./All/$(basename "${_pkg}")
printf '%s\n' "${_have}" | grep -qxF "${_entry}" && continue
if ! tar -tf "${_pkg}" > /dev/null 2>&1; then
# the whole archive is read (a cut one fails), and it is a package
if ! _list=$(tar -tf "${_pkg}" 2> /dev/null) ||
! printf '%s\n' "${_list}" | grep -qx '+MANIFEST'; then
echo ">>> not salvaged, incomplete: ${_entry}"
continue
fi

View file

@ -733,12 +733,21 @@ class SalvagePortsTest(unittest.TestCase):
self.make_pkg(self.stage, "old-1.0.pkg")
subprocess.run(["tar", "-C", setdir, "-cf", self.set, "./.abi_hint", "./All/old-1.0.pkg"], check=True)
def make_pkg(self, d, name, content=b"x" * 5000):
src = os.path.join(self.tmp, "content")
with open(src, "wb") as f:
f.write(os.urandom(2000) + content)
def make_pkg(self, d, name, manifest=True):
# a package as pkg writes it: its manifests first, then the files
src = os.path.join(self.tmp, "pkgsrc")
shutil.rmtree(src, ignore_errors=True)
os.makedirs(os.path.join(src, "usr", "local", "lib"))
members = ["usr/local/lib/libfoo.so"]
with open(os.path.join(src, members[0]), "wb") as f:
f.write(os.urandom(5000))
if manifest:
for m in ("+COMPACT_MANIFEST", "+MANIFEST"):
with open(os.path.join(src, m), "w") as f:
f.write('{"name":"foo"}')
members = ["+COMPACT_MANIFEST", "+MANIFEST"] + members
path = os.path.join(d, name)
subprocess.run(["tar", "-czf", path, "-C", self.tmp, "content"], check=True)
subprocess.run(["tar", "-czf", path, "-C", src, *members], check=True)
return path
def salvage(self, id_=ID, stage=None, set_=None):
@ -801,11 +810,14 @@ class SalvagePortsTest(unittest.TestCase):
data = f.read()
with open(p, "wb") as f:
f.write(data[:len(data) // 2])
# an empty file is an empty archive to FreeBSD's tar
open(os.path.join(self.stage, "empty-1.0.pkg"), "w").close()
self.make_pkg(self.stage, "nomanifest-1.0.pkg", manifest=False)
self.make_pkg(self.stage, "whole-1.0.pkg")
out = self.salvage()
self.assertIn("incomplete: ./All/cut-1.0.pkg", out)
self.assertIn("incomplete: ./All/empty-1.0.pkg", out)
self.assertIn("incomplete: ./All/nomanifest-1.0.pkg", out)
self.assertIn("salvaged 1 packages", out)
self.assertNotIn("./All/cut-1.0.pkg", self.entries())
self.assertIn("./All/whole-1.0.pkg", self.entries())