From 81ea1750346e9bb918878bb7b45ca535a66e4b92 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Fri, 16 Oct 2026 12:11:51 +0300 Subject: [PATCH] bug: always keep existing package version in archive --- .../core/housekeeping/archive_rotation_trigger.py | 7 ++++++- .../housekeeping/test_archive_rotation_trigger.py | 11 +++++++---- docs/configuration.rst | 2 +- docs/triggers.rst | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ahriman-core/src/ahriman/core/housekeeping/archive_rotation_trigger.py b/ahriman-core/src/ahriman/core/housekeeping/archive_rotation_trigger.py index ae826f59..55cc9d56 100644 --- a/ahriman-core/src/ahriman/core/housekeeping/archive_rotation_trigger.py +++ b/ahriman-core/src/ahriman/core/housekeeping/archive_rotation_trigger.py @@ -87,7 +87,12 @@ class ArchiveRotationTrigger(Trigger): if self.keep_built_packages == 0: return - to_remove = repository.package_archives(package.base) + current = next(iter(repository.packages([package.base])), None) + to_remove = [ + single + for single in repository.package_archives(package.base) + if current is None or single.version != current.version + ] for single in to_remove[:-self.keep_built_packages]: self.logger.info("removing version %s of package %s", single.version, single.base) diff --git a/ahriman-core/tests/ahriman/core/housekeeping/test_archive_rotation_trigger.py b/ahriman-core/tests/ahriman/core/housekeeping/test_archive_rotation_trigger.py index be212f4e..458732cc 100644 --- a/ahriman-core/tests/ahriman/core/housekeeping/test_archive_rotation_trigger.py +++ b/ahriman-core/tests/ahriman/core/housekeeping/test_archive_rotation_trigger.py @@ -22,10 +22,10 @@ def test_configuration_sections(configuration: Configuration) -> None: def test_archives_remove(archive_rotation_trigger: ArchiveRotationTrigger, package_ahriman: Package, repository: Repository, mocker: MockerFixture) -> None: """ - must remove older packages + must keep the current package and the configured amount of additional packages """ packages = [] - for i in range(5): + for i in range(1, 7): generated = replace(package_ahriman, version=str(i)) generated.packages = { key: replace(value, filename=str(i)) @@ -33,14 +33,17 @@ def test_archives_remove(archive_rotation_trigger: ArchiveRotationTrigger, packa } packages.append(generated) + archive_rotation_trigger.keep_built_packages = 2 + mocker.patch.object(repository, "packages", return_value=[replace(package_ahriman, version="3")]) mocker.patch("ahriman.core.repository.package_info.PackageInfo.package_archives", return_value=packages) - mocker.patch("pathlib.Path.glob", return_value=[Path(str(i)) for i in range(5)]) + mocker.patch("pathlib.Path.glob", side_effect=lambda pattern: [Path(pattern.removesuffix("*"))]) unlink_mock = mocker.patch("pathlib.Path.unlink", autospec=True) archive_rotation_trigger.archives_remove(package_ahriman, repository) unlink_mock.assert_has_calls([ - MockCall(Path("0")), MockCall(Path("1")), + MockCall(Path("2")), + MockCall(Path("4")), ]) diff --git a/docs/configuration.rst b/docs/configuration.rst index 9f17ac8c..fc5fa643 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -207,7 +207,7 @@ Web server settings. This feature requires ``aiohttp`` libraries to be installed Describes settings for packages archives management extensions. -* ``keep_built_packages`` - keep this amount of built packages with different versions, integer, required. ``0`` will effectively disable archives removal. +* ``keep_built_packages`` - keep this amount of additional built package versions alongside the version currently published in the repository, integer, required. ``0`` will effectively disable archives removal. ``keyring`` group ----------------- diff --git a/docs/triggers.rst b/docs/triggers.rst index f43426ae..6f60ae5f 100644 --- a/docs/triggers.rst +++ b/docs/triggers.rst @@ -44,7 +44,7 @@ This trigger will be called right after build process (``on_result``). It will p ``ahriman.core.housekeeping.ArchiveRotationTrigger`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -This trigger removes old package versions from the archive directory. It implements ``on_result`` and, after each build, compares available versions for updated packages and removes the older ones, keeping only the last N versions as configured by ``keep_built_packages`` option. +This trigger removes old package versions from the archive directory. It implements ``on_result`` and, after each build, compares available versions for updated packages and removes older ones, keeping the version currently published in the repository plus the last N other versions as configured by ``keep_built_packages`` option. ``ahriman.core.housekeeping.LogsRotationTrigger`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^