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

+8
View File
@@ -33,6 +33,14 @@ MARK='#pkgcache-cachefirst '
MANAGED_RE='^baseurl=https://[^ /]+(:[0-9]+)?/(almalinux|epel|remi)/[^ ]+ https://[^ ]+$'
log() { logger -t pkgcache-host-health -p "daemon.$1" -- "${*:2}" 2>/dev/null || true; echo "$1: ${*:2}" >&2; }
# "mode" is read-only and is used by repos.sh sync/status: no lock (a 30 s wait that ends in an
# empty answer would make `sync` think the host is not OFF and revert it), no state dir needed.
if [ "${1:-mode}" = mode ]; then
if grep -q -s -F "$MARK" "$REPO_DIR"/*.repo 2>/dev/null; then echo origin-only
elif grep -q -s -E "$MANAGED_RE" "$REPO_DIR"/*.repo 2>/dev/null; then echo cache-first
else echo off; fi
exit 0
fi
mkdir -p "$STATE_DIR"
exec 9>"$STATE_DIR/lock"; flock -w 30 9 || { echo "lock busy" >&2; exit 0; }
SF="$STATE_DIR/state"