Skip to content

Commit 36746d1

Browse files
committed
fix apt cache timestamp logic
I just stumbled upon a host where there is not `update-success-stamp` at all. Turns out this file is actually site-specific to our environment and is created by a Puppet module we use. It's not standard: the APT::Periodic feature flags updates with the `update-stamp` file instead! So let's split the check into multiple, distinct heuristics: 1. if the `update-success-stamp` file exist, use it and disregard the rest 2. failing that, if `APT::Periodic` is configured, check `update-stamp`, which does roughly the same (but won't update on a plain `apt update`) 3. failing that, check `/var/lib/apt/lists/partial` which *works* but might give a false timestamps when apt-get *fails* to get an update, as that directory's timestamp is always updated Because of (3), we still need the other heuristics. Signed-off-by: Antoine Beaupré <anarcat@debian.org>
1 parent 76a6617 commit 36746d1

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

apt_info.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,20 @@ def _write_autoremove_pending(registry, cache):
9494
def _write_cache_timestamps(registry):
9595
g = Gauge('apt_package_cache_timestamp_seconds', "Apt update last run time.", registry=registry)
9696
apt_pkg.init_config()
97-
if (
98-
apt_pkg.config.find_b("APT::Periodic::Update-Package-Lists") and
99-
os.path.isfile("/var/lib/apt/periodic/update-success-stamp")
100-
):
101-
# if we run updates automatically with APT::Periodic, we can
102-
# check this timestamp file if it exists
97+
if os.path.isfile("/var/lib/apt/periodic/update-success-stamp"):
98+
# this file is often used as a flag file for sucessful runs on
99+
# systems that do not use apt-periodic features, namely
100+
# apt-config-auto-update and the Puppetlabs "apt" puppet
101+
# module.
102+
#
103+
# Example configuration:
104+
#
105+
# APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};
103106
stamp_file = "/var/lib/apt/periodic/update-success-stamp"
107+
elif apt_pkg.config.find_b("APT::Periodic::Update-Package-Lists"):
108+
# if we run updates automatically with APT::Periodic, we can
109+
# check this timestamp file
110+
stamp_file = "/var/lib/apt/periodic/update-stamp"
104111
else:
105112
# if not, let's just fallback on the partial file of the lists directory
106113
stamp_file = '/var/lib/apt/lists/partial'

0 commit comments

Comments
 (0)