如何模拟 Pacman 包?

如何模拟 Pacman 包?

我刚刚完成了一个脚本来打印 Pacman 包中文件的内容(基于pkg-extract_original),但我遇到了麻烦测试最终功能。基本上我有一个测试:

def should_print_file_contents_from_package():
    # Given a dummy package which claims to own a filesystem package file
    package_name = "filesystem"
    file_path = "/etc/hosts"
    file_contents = "Hello World!"
    current_directory = dirname(__file__)
    package_directory = f"{current_directory}/package"
    run(
        ["makepkg", "--force"],
        check=True,
        cwd=package_directory,
        env={
            "PACKAGE_NAME": package_name,
            "FILE_PATH": file_path,
            "FILE_CONTENTS": file_contents,
        },
    )

    # Given the dummy package directory as cache
    environment = {"PACMAN_CONFIG": f"{DIRECTORY}/pacman.conf"}

    # When requesting a file from an installed package
    result = run(
        ["./pacman-package-file.bash", file_path],
        stdout=PIPE,
        check=True,
        env=environment,
    )

    # Then it should print the contents of the build file
    assert result.stdout == file_contents


 a dummy

,一个 PKGBUILD 文件:

#!/usr/bin/env bash

# shellcheck disable=SC2034,SC2154
pkgname="$PACKAGE_NAME"
pkgbase="$PACKAGE_NAME"
version_and_release="$(pacman --query "$PACKAGE_NAME" | cut --delimiter=' ' --fields=2)"
pkgver="$(cut --delimiter='-' --fields=1 <<< "$version_and_release")"
pkgrel="$(cut --delimiter='-' --fields=2 <<< "$version_and_release")"
arch=(any)
package() {
    mkdir --parents "${pkgdir}$(dirname "$FILE_PATH")"
    printf '%s' "$FILE_CONTENTS" > "${pkgdir}${FILE_PATH}"
}

,一个虚拟的 pacman.conf:

[options]
CacheDir    = tests/package

和一个 shell 脚本:

#!/usr/bin/env bash
script_name="$(basename "$0")"

# Add extra pacman parameters if specified
pacman_command=('pacman')
if [[ -n "${PACMAN_CONFIG-}" ]]
then
    pacman_command+=("--config=${PACMAN_CONFIG}")
fi

owners_stderr="${working_directory}/owners_stderr"
mapfile -t owners < <("${pacman_command[@]}" --query --owns --quiet "$1" 2> "$owners_stderr")


owner="${owners[0]}"
package_url="$("${pacman_command[@]}" --sync --print "$owner")"
if [[ "${package_url::7}" != 'file://' ]]
then
    printf "%s: Package missing - download using \`pacman --sync --downloadonly %s\` and retry\n" "$script_name" "$owner" >&2
    exit 9
fi

问题是,即使配置指向虚拟包目录,pacman --cachedir=tests/package --sync --print filesystem也会打印 HTTPS URL,而不是测试/包中文件的路径。

还需要什么才能pacman打印虚拟包文件的路径?

相关内容