Skip to content

Commit

Permalink
Don't retain obsolete packages
Browse files Browse the repository at this point in the history
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 17dc61e (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 eca3a88), the fact of that
obsoletion isn't forgotten once the obsolete package itself is removed.
  • Loading branch information
jon-turney committed Apr 24, 2024
1 parent 4ebc883 commit e1c2bc5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions calm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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', [])
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e1c2bc5

Please sign in to comment.