diff options
author | Luke T. Shumaker <lukeshu@parabola.nu> | 2024-05-10 10:36:12 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@parabola.nu> | 2024-05-10 14:06:04 -0600 |
commit | 61dd990ad1654148f08c1f0987b76bce4df96a11 (patch) | |
tree | f09acce94e246b563d6151db10ca3a82b506f3ef | |
parent | 2127d818b901abdf43df78ec91d0d7880dd01e71 (diff) |
An optimization step in chcleanup turned out to be unsafe in more
scenarios than the comment indicated. I'm sure I felt the optimization
was necessary when I added it in 6faf57c (chcleanup: Try preloading the
scratch DB to speed things up, 2018-08-06). But nowadays I can't imagine
that that's the slow part? idk, remove it.
-rw-r--r-- | src/chroot-tools/chcleanup.in | 14 | ||||
-rw-r--r-- | test/cases/librechroot.bats | 50 | ||||
-rw-r--r-- | test/fixtures/librechroot/PKGBUILD-base-devel | 13 |
3 files changed, 64 insertions, 13 deletions
diff --git a/src/chroot-tools/chcleanup.in b/src/chroot-tools/chcleanup.in index e5e7668..d755f67 100644 --- a/src/chroot-tools/chcleanup.in +++ b/src/chroot-tools/chcleanup.in @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eE # Copyright (C) 2011-2012 Nicolás Reynolds <fauno@parabola.nu> -# Copyright (C) 2012-2013, 2015, 2017-2018 Luke Shumaker <lukeshu@parabola.nu> +# Copyright (C) 2012-2013, 2015, 2017-2018, 2024 Luke T. Shumaker <lukeshu@parabola.nu> # # If you don't see m4_include(...) below, but see function definitions # for msg() et al., then this is a generated file, and contains some @@ -87,18 +87,6 @@ cp -a -t "${TEMPDIR}/db" -- /var/lib/pacman/sync done pacman=(pacman --dbpath="$TEMPDIR/db" --hookdir="$TEMPDIR/hooks") -# Do our best to preload the scratch DB with CHROOTPKG and -# CHROOTEXTRAPKG packages. This is purely an optimization step. The -# safety of this optimization assumes that none of CHROOTPKG, -# CHROOTEXTRAPKG, *or their dependancies* are virtual packages. We -# don't include DEPENDS in this optimization, because this assumption -# doesn't hold for them. -while read -r pkg; do - if [[ -d /var/lib/pacman/local/$pkg ]]; then - cp -a -T -- "/var/lib/pacman/local/$pkg" "$TEMPDIR/db/local/$pkg" - fi -done < <("${pacman[@]}" -Sp --print-format='%n-%v' -- "${CHROOTPKG[@]}" "${CHROOTEXTRAPKG[@]}") - # Get the full list of packages needed by dependencies, including the base system msg2 "Creating a full list of packages..." for var in CHROOTPKG CHROOTEXTRAPKG DEPENDS; do diff --git a/test/cases/librechroot.bats b/test/cases/librechroot.bats index 120dbc3..665c48a 100644 --- a/test/cases/librechroot.bats +++ b/test/cases/librechroot.bats @@ -45,6 +45,56 @@ load ../lib/common } # bats test_tags=network,sudo +@test "librechroot clean-pkgs doesn't remove locally-updated parts of base-devel" { + local copydir="$chrootdir/default/$BATS_TEST_NAME" + + # Get info on the upstream package. + local oldpkgname=libre/pacman + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c "pacman -Sp --print-format='%v %D' ${oldpkgname} >/info.txt" + local oldpkgver pkgdeps + read -r oldpkgver pkgdeps <"$copydir/info.txt" + read -r -a pkgdeps <<<"$pkgdeps" + + # Build our locally-updated version. + local newpkgname="repo/${oldpkgname##*/}" + local newpkgver="${oldpkgver}.1" + mkdir "$tmpdir/workdir/abs" + sed \ + -e "s/@PKGVER@/${newpkgver%%-*}/g" \ + -e "s/@PKGREL@/${newpkgver#*-}/g" \ + -e "s/@PKGDEPS@/${pkgdeps[*]@Q}/g" \ + <fixtures/librechroot/PKGBUILD-base-devel \ + >"$tmpdir/workdir/abs/PKGBUILD" + pushd "$tmpdir/workdir/abs" + testsudo libremakepkg -l "$BATS_TEST_NAME" + popd + testsudo librechroot -l "$BATS_TEST_NAME" run pacman -Sy + + # Verify that the package got added to [repo]... + echo "${newpkgname##*/} $newpkgver" >"$tmpdir/exp.txt" + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c "pacman -Sp --print-format='%n %v' ${newpkgname} >/act.txt" + diff -u "$tmpdir/exp.txt" "$copydir/act.txt" + # ... but not installed. + echo "${oldpkgname##*/} $oldpkgver" >"$tmpdir/exp.txt" + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c "pacman -Q ${oldpkgname##*/} >/act.txt" + diff -u "$tmpdir/exp.txt" "$copydir/act.txt" + + # Run the code-under-test. + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + + # Validate that clean-pkgs didn't change anything. + # + # In [repo]... + echo "${oldpkgname##*/} $oldpkgver" >"$tmpdir/exp.txt" + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c "pacman -Q ${oldpkgname##*/} >/act.txt" + diff -u "$tmpdir/exp.txt" "$copydir/act.txt" + # ... but not installed. + echo "${newpkgname##*/} $newpkgver" >"$tmpdir/exp.txt" + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c "pacman -Sp --print-format='%n %v' ${newpkgname} >/act.txt" + diff -u "$tmpdir/exp.txt" "$copydir/act.txt" +} + +# bats test_tags=network,sudo @test "librechroot clean-pkgs obeys PKGBUILD depends" { # NB: We chown `/startdir` because chcleanup runs `makepkg # --printsrcinfo > .SRCINFO` as the user that owns diff --git a/test/fixtures/librechroot/PKGBUILD-base-devel b/test/fixtures/librechroot/PKGBUILD-base-devel new file mode 100644 index 0000000..ae3b035 --- /dev/null +++ b/test/fixtures/librechroot/PKGBUILD-base-devel @@ -0,0 +1,13 @@ +pkgname=pacman +license=('GPL') +pkgdesc="A library-based package manager with dependency support" +url="https://www.archlinux.org/pacman/" +arch=('x86_64') + +pkgver=@PKGVER@ +pkgrel=@PKGREL@ +depends=(@PKGDEPS@) + +prepare() { :; } +build() { :; } +package() { :; } |