Don't let failed apt updates make package lists look fresh

apt touches /var/lib/apt/lists/partial on every update attempt,
including ones that fail, and the agent took the newest of it and the
two success stamps. So a host whose apt update failed hourly reported
lists an hour old. Use the success stamps (update-success-stamp,
update-stamp) and fall back to lists/partial only when neither exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-11-01 14:53:19 -05:00
1 parent 195fd035e0
commit fa6cca4f64
3 files changed
+34 -8

No files matched your search

+9 -5
View File
@@ -228,18 +228,22 @@ phased_packages() {
}
# Seconds since apt last refreshed its package lists, or empty if unknown.
# Both stamps are touched only after a successful update: update-success-stamp by
# Ubuntu's update-notifier hook and kernelwatch-apt-update.service, update-stamp by
# apt-daily. lists/partial changes on every attempt, failed ones too, so it's only
# a last resort for hosts that have neither (Debian without either timer).
apt_lists_age() {
local newest=0 f m
for f in \
"$ROOT/var/lib/apt/periodic/update-success-stamp" \
"$ROOT/var/lib/apt/periodic/update-stamp" \
"$ROOT/var/lib/apt/lists/partial"; do
[[ -e $f ]] || continue
"$ROOT/var/lib/apt/periodic/update-stamp"; do
m=$(stat -c %Y "$f" 2>/dev/null) || continue
((m > newest)) && newest=$m
done
((newest > 0)) && printf '%s' $(($(date +%s) - newest))
return 0
if ((newest == 0)); then
newest=$(stat -c %Y "$ROOT/var/lib/apt/lists/partial" 2>/dev/null) || return 0
fi
printf '%s' $(($(date +%s) - newest))
}
# Size and free space of the filesystem holding /boot, in KiB, as "SIZE FREE";