Don't retain obsolete packages
authorJon Turney <jon.turney@dronecode.org.uk>
Sun, 19 Jun 2022 12:11:44 +0000 (13:11 +0100)
committerJon Turney <jon.turney@dronecode.org.uk>
Wed, 24 Apr 2024 12:49:28 +0000 (13:49 +0100)
Don't retain obsolete packages over a certain age threshold (when they
are effectively just adding an obsolete: to another package).

This is safe, as commit 17dc61e9 (persisting missing_obsoletes) ensures
that if the obsoletion was old-style (and thus only recorded in the
obsoleted package, with the new-style obsoletes: hint in the obsoleteing
package being synthesized by commit eca3a88d), the fact of that
obsoletion isn't forgotten once the obsolete package itself is removed.

calm/package.py

index 64587e5f977b5a5bd45df351586cc77e2c4dcd10..f21a799b7c94fa80ce25f071c60ad4d2f7042890 100755 (executable)
@@ -1648,7 +1648,7 @@ def mark_package_fresh(packages, p, v, mark=Freshness.fresh):
 # helper function evaluate if package needs marking for conditional retention
 #
 
-def mark_fn(packages, po, v, certain_age, vault_requests):
+def mark_fn(packages, po, v, certain_age, obs_threshold, vault_requests):
     pn = po.name
     bv = po.best_version
 
@@ -1676,6 +1676,17 @@ def mark_fn(packages, po, v, certain_age, vault_requests):
                 logging.debug("deprecated soversion package '%s' version '%s' mtime '%s' is over cut-off age" % (pn, v, time.strftime("%F %T %Z", time.localtime(mtime))))
                 return (Freshness.conditional, True)
 
+    # - package is an old-style obsoletion, over a certain age, and not marked
+    # as self-destruct
+    #
+    if '_obsolete' in po.version_hints[v]['category']:
+        mtime = po.tar(v).mtime
+        if mtime < obs_threshold:
+            provides = po.version_hints[v].get('provides', [])
+            if '_self-destruct' not in provides:
+                logging.debug("obsolete package '%s' version '%s' mtime '%s' is over cut-off age" % (pn, v, time.strftime("%F %T %Z", time.localtime(mtime))))
+                return (Freshness.conditional, False)
+
     # - if package depends on anything in expired_provides
     #
     requires = po.version_hints[v].get('depends', [])
@@ -1700,12 +1711,16 @@ def mark_fn(packages, po, v, certain_age, vault_requests):
 #
 
 SO_AGE_THRESHOLD_YEARS = 5
+OBSOLETE_AGE_THRESHOLD_YEARS = 10
 
 
 def stale_packages(packages, vault_requests):
     certain_age = time.time() - (SO_AGE_THRESHOLD_YEARS * 365.25 * 24 * 60 * 60)
     logging.debug("cut-off date for soversion package to be considered old is %s" % (time.strftime("%F %T %Z", time.localtime(certain_age))))
 
+    obs_threshold = time.time() - (OBSOLETE_AGE_THRESHOLD_YEARS * 365.25 * 24 * 60 * 60)
+    logging.debug("cut-off date for obsolete package to be considered old is %s" % (time.strftime("%F %T %Z", time.localtime(obs_threshold))))
+
     # mark install packages for freshness
     for pn, po in packages.items():
         # mark as fresh any versions explicitly listed in the keep: override
@@ -1763,7 +1778,7 @@ def stale_packages(packages, vault_requests):
         # overwrite with 'conditional' package retention mark if it meets
         # various criteria
         for v in sorted(po.versions(), key=lambda v: SetupVersion(v)):
-            (mark, others) = mark_fn(packages, po, v, certain_age, vault_requests)
+            (mark, others) = mark_fn(packages, po, v, certain_age, obs_threshold, vault_requests)
             if mark != Freshness.fresh:
                 mark_package_fresh(packages, pn, v, mark)
 
This page took 0.057486 seconds and 5 git commands to generate.