Compare commits

..

2 Commits

Author SHA1 Message Date
f92105a132 few review fixes 2026-02-11 22:35:33 +02:00
666c3750ac fix typos 2026-02-11 22:15:30 +02:00
5 changed files with 34 additions and 21 deletions

View File

@@ -25,7 +25,8 @@ from sqlite3 import Connection
from ahriman.application.handlers.handler import Handler from ahriman.application.handlers.handler import Handler
from ahriman.core.alpm.pacman import Pacman from ahriman.core.alpm.pacman import Pacman
from ahriman.core.configuration import Configuration from ahriman.core.configuration import Configuration
from ahriman.core.utils import symlink_relative from ahriman.core.sign.gpg import GPG
from ahriman.core.utils import package_like, symlink_relative
from ahriman.models.package import Package from ahriman.models.package import Package
from ahriman.models.pacman_synchronization import PacmanSynchronization from ahriman.models.pacman_synchronization import PacmanSynchronization
from ahriman.models.repository_paths import RepositoryPaths from ahriman.models.repository_paths import RepositoryPaths
@@ -67,19 +68,19 @@ def move_packages(repository_paths: RepositoryPaths, pacman: Pacman) -> None:
repository_paths(RepositoryPaths): repository paths instance repository_paths(RepositoryPaths): repository paths instance
pacman(Pacman): alpm wrapper instance pacman(Pacman): alpm wrapper instance
""" """
for source in repository_paths.repository.iterdir(): for archive in filter(package_like, repository_paths.repository.iterdir()):
if not source.is_file(follow_symlinks=False): if not archive.is_file(follow_symlinks=False):
continue # skip symbolic links if any continue # skip symbolic links if any
filename = source.name package = Package.from_archive(archive, pacman)
if filename.startswith(".") or ".pkg." not in filename: artifacts = [archive]
# we don't use package_like method here, because it also filters out signatures # check if there are signatures for this package and append it here too
continue if (signature := GPG.signature(archive)).exists():
package = Package.from_archive(source, pacman) artifacts.append(signature)
for source in artifacts:
# move package to the archive directory # move package to the archive directory
target = repository_paths.archive_for(package.base) / filename target = repository_paths.archive_for(package.base) / source.name
source.rename(target) source.rename(target)
# create symlink to the archive # create symlink to the archive
symlink_relative(source, target) symlink_relative(source, target)

View File

@@ -94,7 +94,7 @@ class ArchiveRotationTrigger(Trigger):
comparator: Callable[[Package, Package], int] = lambda left, right: left.vercmp(right.version) comparator: Callable[[Package, Package], int] = lambda left, right: left.vercmp(right.version)
to_remove = sorted(packages.values(), key=cmp_to_key(comparator)) to_remove = sorted(packages.values(), key=cmp_to_key(comparator))
# 0 will imlicitly be tranlsated into [:0], meaning we keep all packages # 0 will implicitly be translated into [:0], meaning we keep all packages
for single in to_remove[:-self.keep_built_packages]: for single in to_remove[:-self.keep_built_packages]:
self.logger.info("removing version %s of package %s", single.version, single.base) self.logger.info("removing version %s of package %s", single.version, single.base)
for archive in single.packages.values(): for archive in single.packages.values():

View File

@@ -111,10 +111,10 @@ class Executor(PackageInfo, Cleaner):
if prebuilt := list(self._archive_lookup(loaded_package)): if prebuilt := list(self._archive_lookup(loaded_package)):
self.logger.info("using prebuilt packages for %s-%s", loaded_package.base, loaded_package.version) self.logger.info("using prebuilt packages for %s-%s", loaded_package.base, loaded_package.version)
built = [] built = []
for artefact in prebuilt: for artifact in prebuilt:
with filelock(artefact): with filelock(artifact):
shutil.copy(artefact, path) shutil.copy(artifact, path)
built.append(path / artefact.name) built.append(path / artifact.name)
else: else:
built = task.build(path, PACKAGER=packager) built = task.build(path, PACKAGER=packager)

View File

@@ -282,7 +282,9 @@ def filelock(path: Path) -> Iterator[None]:
finally: finally:
fcntl.flock(fd, fcntl.LOCK_UN) # unlock file first fcntl.flock(fd, fcntl.LOCK_UN) # unlock file first
finally: finally:
lock_path.unlink(missing_ok=True) # remove lock file at the end # remove lock file at the end
# there might be a race condition here, but we don't care about this case
lock_path.unlink(missing_ok=True)
def filter_json(source: dict[str, Any], known_fields: Iterable[str]) -> dict[str, Any]: def filter_json(source: dict[str, Any], known_fields: Iterable[str]) -> dict[str, Any]:

View File

@@ -47,10 +47,12 @@ def test_move_packages(repository_paths: RepositoryPaths, pacman: Pacman, packag
repository_paths.repository / "directory", repository_paths.repository / "directory",
repository_paths.repository / "file.pkg.tar.xz", repository_paths.repository / "file.pkg.tar.xz",
repository_paths.repository / "file.pkg.tar.xz.sig", repository_paths.repository / "file.pkg.tar.xz.sig",
repository_paths.repository / "file2.pkg.tar.xz",
repository_paths.repository / "symlink.pkg.tar.xz", repository_paths.repository / "symlink.pkg.tar.xz",
]) ])
mocker.patch("pathlib.Path.is_dir", return_value=True) mocker.patch("pathlib.Path.is_dir", return_value=True)
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=is_file) mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=is_file)
mocker.patch("pathlib.Path.exists", return_value=True)
archive_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman) archive_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
rename_mock = mocker.patch("pathlib.Path.rename") rename_mock = mocker.patch("pathlib.Path.rename")
symlink_mock = mocker.patch("pathlib.Path.symlink_to") symlink_mock = mocker.patch("pathlib.Path.symlink_to")
@@ -58,11 +60,12 @@ def test_move_packages(repository_paths: RepositoryPaths, pacman: Pacman, packag
move_packages(repository_paths, pacman) move_packages(repository_paths, pacman)
archive_mock.assert_has_calls([ archive_mock.assert_has_calls([
MockCall(repository_paths.repository / "file.pkg.tar.xz", pacman), MockCall(repository_paths.repository / "file.pkg.tar.xz", pacman),
MockCall(repository_paths.repository / "file.pkg.tar.xz.sig", pacman), MockCall(repository_paths.repository / "file2.pkg.tar.xz", pacman),
]) ])
rename_mock.assert_has_calls([ rename_mock.assert_has_calls([
MockCall(repository_paths.archive_for(package_ahriman.base) / "file.pkg.tar.xz"), MockCall(repository_paths.archive_for(package_ahriman.base) / "file.pkg.tar.xz"),
MockCall(repository_paths.archive_for(package_ahriman.base) / "file.pkg.tar.xz.sig"), MockCall(repository_paths.archive_for(package_ahriman.base) / "file.pkg.tar.xz.sig"),
MockCall(repository_paths.archive_for(package_ahriman.base) / "file2.pkg.tar.xz"),
]) ])
symlink_mock.assert_has_calls([ symlink_mock.assert_has_calls([
MockCall( MockCall(
@@ -79,4 +82,11 @@ def test_move_packages(repository_paths: RepositoryPaths, pacman: Pacman, packag
repository_paths.archive_for(package_ahriman.base).relative_to(repository_paths.root) / repository_paths.archive_for(package_ahriman.base).relative_to(repository_paths.root) /
"file.pkg.tar.xz.sig" "file.pkg.tar.xz.sig"
), ),
MockCall(
Path("..") /
".." /
".." /
repository_paths.archive_for(package_ahriman.base).relative_to(repository_paths.root) /
"file2.pkg.tar.xz"
),
]) ])