gwmirror publish: refuse to delete a series from the share
publish mirrors the staged tree with rsync --delete-after, and the share holds the only copy of series that are no longer built (26.1). A staging tree rebuilt after /scratch was lost, holding only the current series, would have deleted 26.1 from the live mirror. publish now stops, before verifying, when the destination has a directory in its top two levels (an ABI, a series, releases/<series>) that the staged tree lacks; names are printed quoted. Retiring a series means deleting it from the share by hand. RELEASE.md documents the guard and how to restore the staged tree from the share. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb138079b7
commit
49db816186
3 changed files with 123 additions and 1 deletions
23
RELEASE.md
23
RELEASE.md
|
|
@ -406,7 +406,11 @@ Nothing is extracted to disk while verifying.
|
|||
`--url` is shallow by default (sizes and signatures, no downloads beyond the
|
||||
catalogues). `--deep` downloads and hashes everything.
|
||||
|
||||
**`publish`** refuses to copy a tree that fails verification. It then runs
|
||||
**`publish`** first refuses to delete a series. If the destination has a
|
||||
directory in its top two levels (`FreeBSD_14_aarch64`,
|
||||
`FreeBSD_14_aarch64/26.1`, `releases/26.1`) that the staged tree lacks, it
|
||||
stops before verifying. A series is retired by deleting it from the share by
|
||||
hand. `publish` then refuses to copy a tree that fails verification, and runs
|
||||
`rsync -rtL --delay-updates --delete-after`: symlinks become plain files
|
||||
(SMB keeps none), and clients never see a half-written repository.
|
||||
|
||||
|
|
@ -424,6 +428,23 @@ needs no privileges:
|
|||
and nothing else may live in that folder: `--delete-after` removes it. The
|
||||
container's `SMB_SHARE` names the same folder (`<share>/mirror`).
|
||||
|
||||
### Restoring the staged mirror
|
||||
|
||||
The staged tree in `/scratch` is a working copy, and the share holds the
|
||||
only copy of series that are no longer built (26.1 since 2026-11-28). If
|
||||
`/scratch` is lost, copy the share back, then re-stage the current build so
|
||||
its symlinks and hard links return (the rest stays as plain copies, which
|
||||
verify the same way):
|
||||
|
||||
```sh
|
||||
M=/scratch/mono-opnsense/mirror
|
||||
mkdir -p $M && rsync -rt /mnt/opnsense-mirror/ $M/
|
||||
release/vm.sh pull-out 15.1 26.7
|
||||
python3 mirror/gwmirror.py stage --sets /scratch/mono-opnsense/out/26.7 --mirror $M --series 26.7 --version 26.7.9 --upgrade-from 26.1
|
||||
python3 mirror/gwmirror.py verify --root $M
|
||||
rsync -rL -n -i -c --delete-after --exclude='.*' $M/ /mnt/opnsense-mirror/ # prints nothing: publish would change no content
|
||||
```
|
||||
|
||||
## Serving the mirror
|
||||
|
||||
`mirror/server/` holds the stack:
|
||||
|
|
|
|||
|
|
@ -963,9 +963,34 @@ def stage(args):
|
|||
return 0
|
||||
|
||||
|
||||
def dropped_dirs(mirror, dest):
|
||||
"""Directories in the top two levels of dest (FreeBSD_14_aarch64, its 26.1,
|
||||
releases/26.1) that the staged mirror lacks: publishing would delete them,
|
||||
and with them a whole series. Dotfiles are skipped, as publish skips them."""
|
||||
dropped = []
|
||||
for top in sorted(os.listdir(dest)):
|
||||
d, m = os.path.join(dest, top), os.path.join(mirror, top)
|
||||
if top.startswith(".") or not os.path.isdir(d):
|
||||
continue
|
||||
if not os.path.isdir(m):
|
||||
dropped.append(top)
|
||||
continue
|
||||
dropped.extend(f"{top}/{sub}" for sub in sorted(os.listdir(d))
|
||||
if not sub.startswith(".") and os.path.isdir(os.path.join(d, sub))
|
||||
and not os.path.isdir(os.path.join(m, sub)))
|
||||
return dropped
|
||||
|
||||
|
||||
def publish(args):
|
||||
if not os.path.isdir(args.dest):
|
||||
raise SystemExit(f"gwmirror publish: destination {args.dest} is not a directory")
|
||||
dropped = dropped_dirs(args.mirror, args.dest)
|
||||
if dropped:
|
||||
print(f"gwmirror publish: {', '.join(map(repr, dropped))} in {args.dest} would be deleted: "
|
||||
"the staged mirror lacks them. Restore them into it (RELEASE.md, \"Restoring the "
|
||||
"staged mirror\"), or delete them from the destination to retire them. "
|
||||
"Nothing published", file=sys.stderr)
|
||||
return 1
|
||||
vargs = argparse.Namespace(root=args.mirror, url=None, series=None, shallow=False,
|
||||
fingerprints=args.fingerprints,
|
||||
upstream_fingerprints=args.upstream_fingerprints,
|
||||
|
|
|
|||
|
|
@ -910,6 +910,82 @@ class PublishTest(Base):
|
|||
with self.assertRaises(SystemExit):
|
||||
g.main(["publish", "--mirror", self.mirror, "--dest", os.path.join(self.tmp, "nope")])
|
||||
|
||||
def publish(self, dest):
|
||||
return run_main(["publish", "--mirror", self.mirror, "--dest", dest,
|
||||
"--fingerprints", self.keys.ours, "--upstream-fingerprints", self.keys.upstream])
|
||||
|
||||
def published_dest(self):
|
||||
"""A destination holding an earlier publish of the staged mirror."""
|
||||
self.staged()
|
||||
dest = os.path.join(self.tmp, "dest")
|
||||
os.makedirs(dest)
|
||||
code, text = self.publish(dest)
|
||||
self.assertEqual(code, 0, text)
|
||||
return dest
|
||||
|
||||
def assertRefusedKeeps(self, dest, *dropped):
|
||||
before = sorted(os.path.relpath(os.path.join(d, n), dest)
|
||||
for d, dirs, files in os.walk(dest) for n in dirs + files)
|
||||
with mock.patch.object(g, "verify", side_effect=AssertionError("refused before the verify")):
|
||||
code, text = self.publish(dest)
|
||||
self.assertEqual(code, 1, text)
|
||||
self.assertIn("would be deleted", text)
|
||||
self.assertIn(", ".join(map(repr, dropped)) + " in ", text)
|
||||
after = sorted(os.path.relpath(os.path.join(d, n), dest)
|
||||
for d, dirs, files in os.walk(dest) for n in dirs + files)
|
||||
self.assertEqual(before, after)
|
||||
|
||||
def test_publish_refuses_to_drop_a_series(self):
|
||||
# a fresh staging tree that holds only the new series: the old one is still live
|
||||
dest = self.published_dest()
|
||||
os.makedirs(os.path.join(dest, "FreeBSD_15_aarch64", "26.7", "latest"))
|
||||
open(os.path.join(dest, "FreeBSD_15_aarch64", "26.7", "latest", "meta.conf"), "w").close()
|
||||
self.assertRefusedKeeps(dest, "FreeBSD_15_aarch64")
|
||||
os.makedirs(os.path.join(self.mirror, "FreeBSD_15_aarch64"))
|
||||
self.assertRefusedKeeps(dest, "FreeBSD_15_aarch64/26.7")
|
||||
|
||||
def test_publish_refuses_to_drop_release_images(self):
|
||||
dest = self.published_dest()
|
||||
old = os.path.join(dest, "releases", "26.0")
|
||||
os.makedirs(old)
|
||||
open(os.path.join(old, "OPNsense-26.0.1-arm-aarch64-GATEWAY.img.gz"), "w").close()
|
||||
shutil.rmtree(os.path.join(self.mirror, "releases", SERIES))
|
||||
self.assertRefusedKeeps(dest, "releases/26.0", f"releases/{SERIES}")
|
||||
|
||||
def test_publish_lists_hostile_names_quoted(self):
|
||||
dest = self.published_dest()
|
||||
os.makedirs(os.path.join(dest, "x\x1b[2J"))
|
||||
code, text = self.publish(dest)
|
||||
self.assertEqual(code, 1, text)
|
||||
self.assertNotIn("\x1b", text)
|
||||
self.assertIn(r"'x\x1b[2J'", text)
|
||||
|
||||
def test_publish_still_deletes_below_series_level(self):
|
||||
# stale files inside a series, and top-level files, go as before
|
||||
dest = self.published_dest()
|
||||
d = os.path.join(dest, DISK_ABI, SERIES)
|
||||
os.makedirs(os.path.join(d, "MINT", "26.1.10", "latest"))
|
||||
open(os.path.join(d, "sets", "base-26.1.10-aarch64.txz"), "w").close()
|
||||
open(os.path.join(dest, "stale"), "w").close()
|
||||
os.makedirs(os.path.join(dest, ".snapshot"))
|
||||
code, text = self.publish(dest)
|
||||
self.assertEqual(code, 0, text)
|
||||
self.assertFalse(os.path.exists(os.path.join(d, "MINT", "26.1.10")))
|
||||
self.assertFalse(os.path.exists(os.path.join(d, "sets", "base-26.1.10-aarch64.txz")))
|
||||
self.assertFalse(os.path.exists(os.path.join(dest, "stale")))
|
||||
self.assertTrue(os.path.isdir(os.path.join(dest, ".snapshot")), "dotfiles are not ours")
|
||||
|
||||
def test_restored_staging_tree_verifies_and_publishes(self):
|
||||
# RELEASE.md's restore: copy the published tree back, links and all gone
|
||||
dest = self.published_dest()
|
||||
shutil.rmtree(self.mirror)
|
||||
shutil.copytree(dest, self.mirror)
|
||||
self.assertEqual(g.dropped_dirs(self.mirror, dest), [])
|
||||
code, text = self.verify()
|
||||
self.assertEqual(code, 0, text)
|
||||
code, text = self.publish(dest)
|
||||
self.assertEqual(code, 0, text)
|
||||
|
||||
|
||||
|
||||
class Blake2Catalogue:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue