pkgcache host: lock-free 'mode', atomic apply/revert file writes, shared repo lock

- health 'mode' took the 30 s flock and mkdir'd the state dir; a held lock gave an empty
  answer, which sync (OFF) read as 'not off' and reverted from the newest backup. mode is
  now read-only and lock-free.
- apply's rewrite() truncated repo files in place and revert used cp -a over the file;
  both now write a temp file and rename(2), so a concurrent dnf never sees half a file.
- apply/revert take the same lock as the health timer so a health run cannot rewrite
  repo files while they edit them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-29 07:31:56 -08:00
1 parent b28e561387
commit ebe635501d
3 files changed
+37 -6

No files matched your search

+4
View File
@@ -82,6 +82,10 @@ FAKE_CACHE=refused FAKE_ORIGIN=down "$HL" run 2>/dev/null; FAKE_CACHE=refused FA
[ "$("$HL" mode)" = cache-first ] && ok "cache+origin both down: no fallback" || bad "network outage caused a fallback"
FAKE_CACHE=refused "$HL" run 2>/dev/null; FAKE_CACHE=refused "$HL" run 2>/dev/null; [ "$("$HL" mode)" = origin-only ] && ok "connection refused counts as failure" || bad "refused not counted"
# mode must not wait for the health lock (a held lock once turned `mode` into an empty answer)
( flock 9; sleep 4 ) 9>"$T/state/lock" & sleep 0.5
m=$(timeout 3 "$HL" mode || true); [ "$m" = origin-only ] && ok "mode answers while the health lock is held" || bad "mode blocked on the lock (got '$m')"
wait
# ---- OFF via setting reverts cleanly, even from origin-only ----
echo "PKGCACHE_ENABLED=0" >"$T/pkgcache-host.conf"; printf 'PKGCACHE_CA=%s\n' "$T/ca.crt" >>"$T/pkgcache-host.conf"
"$R" sync >/dev/null