mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-04-07 11:03:37 +00:00
few review fixes
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
# move package to the archive directory
|
for source in artifacts:
|
||||||
target = repository_paths.archive_for(package.base) / filename
|
# move package to the archive directory
|
||||||
source.rename(target)
|
target = repository_paths.archive_for(package.base) / source.name
|
||||||
|
source.rename(target)
|
||||||
# create symlink to the archive
|
# create symlink to the archive
|
||||||
symlink_relative(source, target)
|
symlink_relative(source, target)
|
||||||
|
|||||||
@@ -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]:
|
||||||
|
|||||||
@@ -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"
|
||||||
|
),
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user