diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2018-09-20 18:23:53 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@parabola.nu> | 2018-10-07 19:00:51 -0400 |
commit | 244745441b11a3e734892fd406491480716dc2e9 (patch) | |
tree | 2d52c83c34e540ac7063d92bf7d50cfa11560d51 | |
parent | cce008fe13b4c820ac914b92910963baa0fba5d8 (diff) |
db-move, db-remove: Require explicitly prefixing "pkgname=" to use pkgname
instead of pkgbase
This makes it harder to accidentally do the wrong thing and easier to say
"this is exactly what I mean."
When using "pkgname=", it won't vcs_move or vcs_remove the package. Which
is... fine, since if you gave it a pkgname before it was broken anyway, as
they expect a pkgbase. Perhaps they should track which members of a
split package have been moved/removed?
This reverts commit 2d3abfdc8bb035f4ae0b652c1362c68ca10e76e2.
-rw-r--r-- | db-functions | 12 | ||||
-rwxr-xr-x | db-move | 52 | ||||
-rwxr-xr-x | db-remove | 30 | ||||
-rwxr-xr-x | test/cases/db-move.bats | 17 | ||||
-rwxr-xr-x | test/cases/db-remove.bats | 21 |
5 files changed, 90 insertions, 42 deletions
diff --git a/db-functions b/db-functions index d91a7f2..1d4358c 100644 --- a/db-functions +++ b/db-functions @@ -459,18 +459,22 @@ arch_expac() { expac --config="${dir}/pacman.conf" --sync "${args[@]}" } -# usage: arch_expac_pkgbase repo arch format <pkgname|pkgbase> -# Like arch_expac, but 'target' may be a pkgbase, instead of the usual -# pkgname. +# usage: arch_expac_pkgbase repo arch format pkgbase +# Like arch_expac, but 'target' is a pkgbase rather than a pkgname. # Only accepts one target. arch_expac_pkgbase() { local repo=$1 local arch=$2 local format=$3 local pkgbase=$4 + # makepkg <5.1 didn't set pkgbase in .PKGINFO for non-split + # packages when when pkgbase==pkgname; so until all packages + # have been rebuilt with makepkg 5.1, we need to look at + # pkgbase (%e) and pkgname (%n) when filtering based on + # pkgbase. arch_expac "$repo" "$arch" "%e %n $format" | awk -F' ' -v pkgbase="$pkgbase" \ - '$1 == pkgbase || $2 == pkgbase' | + '$1 == pkgbase || ($1 == "(null)" && $2 == pkgbase)' | cut -d' ' -f3- } @@ -4,7 +4,8 @@ . "$(dirname "$(readlink -e "$0")")/db-functions" if (( $# < 3 )); then - msg "usage: %s <repo-from> <repo-to> <pkgname|pkgbase> ..." "${0##*/}" + msg "usage: %s <repo-from> <repo-to> <pkgbase> ..." "${0##*/}" + msg " or: %s <repo-from> <repo-to> pkgname=<pkgname> ..." "${0##*/}" exit 1 fi @@ -25,10 +26,11 @@ for pkgarch in "${ARCHES[@]}"; do done # First loop is to check that all necessary files exist -for pkgbase in "${args[@]:2}"; do +for pkg in "${args[@]:2}"; do found=false for tarch in "${ARCHES[@]}"; do - while read -r pkgfile; do + while read -r pkgbase pkgname pkgfile; do + [[ $pkgbase != '(null)' ]] || pkgbase=$pkgname if ! vcs_move_preflight_check "$repo_from" "$tarch" "$pkgbase"; then die "%s not found in %s-%s" "$pkgbase" "$repo_from" "$tarch" @@ -39,9 +41,15 @@ for pkgbase in "${args[@]:2}"; do getpkgfile "${ftppath_from}/${tarch}/${pkgfile}" >/dev/null found=true - done < <(arch_expac_pkgbase "$repo_from" "$tarch" '%f' "$pkgbase") + done < <( + if [[ $pkg = 'pkgname='* ]]; then + arch_expac "$repo_from" "$tarch" '%e %n %f' "${pkg#pkgname=}" + else + arch_expac_pkgbase "$repo_from" "$tarch" '%e %n %f' "$pkg" + fi + ) done - [[ $found = true ]] || die "%s not found in %s" "$pkgbase" "$repo_from" + [[ $found = true ]] || die "%s not found in %s" "$pkg" "$repo_from" done msg "Moving packages from [%s] to [%s]..." "$repo_from" "$repo_to" @@ -50,22 +58,20 @@ for arch in "${ARCHES[@]}"; do declare -a add_pkgs_$arch declare -a remove_pkgs_$arch done -for pkgbase in "${args[@]:2}"; do - vcs_move_start "$repo_from" "$repo_to" "$pkgbase" +for pkg in "${args[@]:2}"; do + if [[ $pkg != 'pkgname='* ]]; then + vcs_move_start "$repo_from" "$repo_to" "$pkg" + fi for tarch in "${ARCHES[@]}"; do - msg2 "%s (%s)" "$pkgbase" "$tarch" + msg2 "%s (%s)" "$pkg" "$tarch" declare -n add_pkgs="add_pkgs_${tarch}" declare -n remove_pkgs="remove_pkgs_${tarch}" - vcs_move_arch "$tarch" - while read -r _pkgbase pkgname pkgver pkgfile; do + if [[ $pkg != 'pkgname='* ]]; then + vcs_move_arch "$tarch" + fi + while read -r pkgbase pkgname pkgver pkgfile; do + [[ $pkgbase != '(null)' ]] || pkgbase=$pkgname plain 'pkgname=%s (%s)' "$pkgname" "$pkgver" - [[ $_pkgbase != '(null)' ]] || _pkgbase=$pkgname - [[ $_pkgbase != '(null)' ]] || _pkgbase=$pkgname - if [[ $_pkgbase != $pkgbase ]]; then - warning "'%s' is a member of pkgbase=%s" "$pkgname" "$_pkgbase" - warning "It is the only member being removed;" - warning "you will need to move the others yourself!" - fi ln -s "../../../${PKGPOOL}/${pkgfile}" "${ftppath_to}/${tarch}/" if [[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile}.sig ]]; then @@ -73,9 +79,17 @@ for pkgbase in "${args[@]:2}"; do fi add_pkgs+=("${FTP_BASE}/${PKGPOOL}/${pkgfile}") remove_pkgs+=("${pkgname}") - done < <(arch_expac_pkgbase "$repo_from" "$tarch" '%e %n %v %f' "$pkgbase") + done < <( + if [[ $pkg = 'pkgname='* ]]; then + arch_expac "$repo_from" "$tarch" '%e %n %v %f' "${pkg#pkgname=}" + else + arch_expac_pkgbase "$repo_from" "$tarch" '%e %n %v %f' "$pkg" + fi + ) done - vcs_move_finish + if [[ $pkg != 'pkgname='* ]]; then + vcs_move_finish + fi done for tarch in "${ARCHES[@]}"; do @@ -4,13 +4,14 @@ . "$(dirname "$(readlink -e "$0")")/db-functions" if (( $# < 3 )); then - msg "usage: %s <repo> <arch> <pkgname|pkgbase> ..." "${0##*/}" + msg "usage: %s <repo> <arch> <pkgbase> ..." "${0##*/}" + msg " or: %s <repo> <arch> pkgname=<pkgname> ..." "${0##*/}" exit 1 fi repo="$1" arch="$2" -pkgbases=("${@:3}") +pkgs=("${@:3}") if ! check_repo_permission "$repo"; then die "You don't have permission to remove packages from %s" "$repo" @@ -28,28 +29,31 @@ for tarch in "${tarches[@]}"; do repo_lock "$repo" "$tarch" || exit 1 declare -a remove_pkgs_$tarch done -for pkgbase in "${pkgbases[@]}"; do +for pkg in "${pkgs[@]}"; do for tarch in "${tarches[@]}"; do - msg2 "%s (%s)" "$pkgbase" "$tarch" + msg2 "%s (%s)" "$pkg" "$tarch" declare -n remove_pkgs="remove_pkgs_${tarch}" # We could just use %n and a single `mapfile`, but # getting extra info and printing everything is more # user-friendly. found=false - while read -r _pkgbase pkgname pkgver; do + while read -r pkgbase pkgname pkgver; do + [[ $pkgbase != '(null)' ]] || pkgbase=$pkgname plain 'pkgname=%s (%s)' "${pkgname}" "$pkgver" - [[ $_pkgbase != '(null)' ]] || _pkgbase=$pkgname - if [[ $_pkgbase != $pkgbase ]]; then - warning "'%s' is a member of pkgbase=%s" "$pkgname" "$_pkgbase" - warning "It is the only member being removed;" - warning "you will need to remove the others yourself!" - fi remove_pkgs+=("${pkgname}") found=true - done < <(arch_expac_pkgbase "$repo" "$tarch" '%e %n %v' "$pkgbase") + done < <( + if [[ $pkg = 'pkgname='* ]]; then + arch_expac "$repo" "$tarch" '%e %n %v' "${pkg#pkgname=}" + else + arch_expac_pkgbase "$repo" "$tarch" '%e %n %v' "$pkg" + fi + ) [[ $found = true ]] || plain '(none)' - vcs_remove "$repo" "$tarch" "$pkgbase" + if [[ $pkg != 'pkgname='* ]]; then + vcs_remove "$repo" "$tarch" "$pkg" + fi done done diff --git a/test/cases/db-move.bats b/test/cases/db-move.bats index 216ebf7..31ec7c5 100755 --- a/test/cases/db-move.bats +++ b/test/cases/db-move.bats @@ -106,15 +106,28 @@ load ../lib/common checkPackage testing pkg-split-b 1-1 } -@test "move partial split packages" { +@test "move partial split packages explicitly" { local pkgs=('pkg-split-a') releasePackage testing pkg-split-a db-update - db-move testing extra pkg-split-a1 + db-move testing extra pkgname=pkg-split-a1 bsdtar xfO "$FTP_BASE/extra/os/x86_64/extra.db" pkg-split-a1-1-1/desc >/dev/null if bsdtar xfO "$FTP_BASE/testing/os/x86_64/testing.db" pkg-split-a1-1-1/desc >/dev/null; then return 1; fi bsdtar xfO "$FTP_BASE/testing/os/x86_64/testing.db" pkg-split-a2-1-1/desc >/dev/null if bsdtar xfO "$FTP_BASE/extra/os/x86_64/extra.db" pkg-split-a2-1-1/desc >/dev/null; then return 1; fi } + +@test "move partial split packages implicitly fails" { + local pkgs=('pkg-split-a') + + releasePackage testing pkg-split-a + db-update + if db-move testing extra pkg-split-a1; then return 1; fi + + bsdtar xfO "$FTP_BASE/testing/os/x86_64/testing.db" pkg-split-a1-1-1/desc >/dev/null + bsdtar xfO "$FTP_BASE/testing/os/x86_64/testing.db" pkg-split-a2-1-1/desc >/dev/null + if bsdtar xfO "$FTP_BASE/extra/os/x86_64/extra.db" pkg-split-a1-1-1/desc >/dev/null; then return 1; fi + if bsdtar xfO "$FTP_BASE/extra/os/x86_64/extra.db" pkg-split-a2-1-1/desc >/dev/null; then return 1; fi +} diff --git a/test/cases/db-remove.bats b/test/cases/db-remove.bats index 06a5f2f..c7b4b02 100755 --- a/test/cases/db-remove.bats +++ b/test/cases/db-remove.bats @@ -44,7 +44,7 @@ load ../lib/common done } -@test "remove partial split package" { +@test "remove partial split package explicitly" { local arches=('i686' 'x86_64') local arch @@ -52,11 +52,24 @@ load ../lib/common db-update for arch in ${arches[@]}; do - db-remove extra "${arch}" pkg-split-a1 + db-remove extra "${arch}" pkgname=pkg-split-a1 + if bsdtar xfO "$FTP_BASE/extra/os/$arch/extra.db" pkg-split-a1-1-1/desc >/dev/null; then return 1; fi + bsdtar xfO "$FTP_BASE/extra/os/$arch/extra.db" pkg-split-a2-1-1/desc >/dev/null done +} + +@test "remove partial split package implicitly fails" { + local arches=('i686' 'x86_64') + local arch - if bsdtar xfO "$FTP_BASE/extra/os/x86_64/extra.db" pkg-split-a1-1-1/desc >/dev/null; then return 1; fi - bsdtar xfO "$FTP_BASE/extra/os/x86_64/extra.db" pkg-split-a2-1-1/desc >/dev/null + releasePackage extra pkg-split-a + db-update + + for arch in ${arches[@]}; do + db-remove extra "${arch}" pkg-split-a1 + bsdtar xfO "$FTP_BASE/extra/os/x86_64/extra.db" pkg-split-a1-1-1/desc >/dev/null + bsdtar xfO "$FTP_BASE/extra/os/x86_64/extra.db" pkg-split-a2-1-1/desc >/dev/null + done } @test "remove split multilib package" { |