From 99ca0cb2fd43879ee18890d941037634f978d182 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Thu, 4 Apr 2024 12:35:30 +0300 Subject: [PATCH] fix: update Repo.init to the latest pacman release --- src/ahriman/core/alpm/repo.py | 11 ++++++++--- tests/ahriman/core/alpm/test_repo.py | 23 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/ahriman/core/alpm/repo.py b/src/ahriman/core/alpm/repo.py index 22a51544..049073c1 100644 --- a/src/ahriman/core/alpm/repo.py +++ b/src/ahriman/core/alpm/repo.py @@ -68,7 +68,7 @@ class Repo(LazyLogging): path(Path): path to archive to add """ check_output( - "repo-add", *self.sign_args, "-R", str(self.repo_path), str(path), + "repo-add", *self.sign_args, "--remove", str(self.repo_path), str(path), exception=BuildError.from_process(path.name), cwd=self.paths.repository, logger=self.logger, @@ -78,8 +78,13 @@ class Repo(LazyLogging): """ create empty repository database. It just calls add with empty arguments """ - check_output("repo-add", *self.sign_args, str(self.repo_path), - cwd=self.paths.repository, logger=self.logger, user=self.uid) + # since pacman-6.1.0 repo-add doesn't create empty database in case if no packages supplied + # this code creates empty files instead + if self.repo_path.exists(): + return # database is already created, skip this part + + self.repo_path.touch(exist_ok=True) + (self.paths.repository / f"{self.name}.db").symlink_to(self.repo_path) def remove(self, package: str, filename: Path) -> None: """ diff --git a/tests/ahriman/core/alpm/test_repo.py b/tests/ahriman/core/alpm/test_repo.py index db52b1e3..03714216 100644 --- a/tests/ahriman/core/alpm/test_repo.py +++ b/tests/ahriman/core/alpm/test_repo.py @@ -26,13 +26,28 @@ def test_repo_add(repo: Repo, mocker: MockerFixture) -> None: def test_repo_init(repo: Repo, mocker: MockerFixture) -> None: """ - must call repo-add with empty package list on repo initializing + must create empty database files """ - check_output_mock = mocker.patch("ahriman.core.alpm.repo.check_output") + mocker.patch("pathlib.Path.exists", return_value=False) + touch_mock = mocker.patch("pathlib.Path.touch") + symlink_mock = mocker.patch("pathlib.Path.symlink_to") repo.init() - check_output_mock.assert_called_once() # it will be checked later - assert check_output_mock.call_args[0][0] == "repo-add" + touch_mock.assert_called_once_with(exist_ok=True) + symlink_mock.assert_called_once_with(repo.repo_path) + + +def test_repo_init_skip(repo: Repo, mocker: MockerFixture) -> None: + """ + must do not create files if database already exists + """ + mocker.patch("pathlib.Path.exists", return_value=True) + touch_mock = mocker.patch("pathlib.Path.touch") + symlink_mock = mocker.patch("pathlib.Path.symlink_to") + + repo.init() + touch_mock.assert_not_called() + symlink_mock.assert_not_called() def test_repo_remove(repo: Repo, mocker: MockerFixture) -> None: