Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/downgrade
Original file line number Diff line number Diff line change
Expand Up @@ -577,17 +577,20 @@ build_pkg() {
commit_hash=$(sed -r "s/$gitpkgreg/\3/" <<<"$item")

pushd "$path" >/dev/null
su -P "$(stat -c"%U" PKGBUILD)" -c "git checkout $commit_hash &>/dev/null && makepkg -fs | tee makepkg.log"
su -P "$(stat -c"%U" PKGBUILD)" -c "git checkout $commit_hash &>/dev/null && makepkg -fs"
build_failed=$?

if ((!build_failed)); then
item=$(su "$(stat -c"%U" PKGBUILD)" -c "makepkg --packagelist" | head -n 1)
fi

# NOTE: when force-canceling, users might need to manually do checkout master
# otherwise they won't be able to update that pkg using yay or whatever I guess...
su "$(stat -c"%U" PKGBUILD)" -c "git switch - &>/dev/null"
if ((build_failed)); then
exit 1
fi

item="$(find "$path" -maxdepth 1 -type f -name "$(sed -nr '/.*Finished making: ([^ ]+) ([^ ]+) .*/{s//\1-\2/;p}' makepkg.log)*" -print -quit)"
rm makepkg.log
popd >/dev/null
fi
printf "%s\0" "$item" >>new_to_install.downgrade
Expand Down
47 changes: 47 additions & 0 deletions test/build_pkg/main.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
$ source "$TESTDIR/../helper.sh"
> su() {
> local cmd
> while [[ $# -gt 0 ]]; do
> if [[ "$1" == "-c" ]]; then cmd="$2"; break; fi
> shift
> done
> case "$cmd" in
> *"makepkg -fs"*) return "${MAKEPKG_FAIL:-0}" ;;
> git*) return 0 ;;
> "makepkg --packagelist") echo "/tmp/dummy-package-1.0-1-any.pkg.tar.zst" ;;
> esac
> }
> stat() { echo "testuser"; }
> tmpdir=$(mktemp -d)
> touch "$tmpdir/PKGBUILD"

Build success: makepkg --packagelist output is written to file

$ cd "$tmpdir"
> MAKEPKG_FAIL=0
> build_pkg "$tmpdir/dummy-package-1.0-g123456-any.gitpkg.tar.gz"; exit_code=$?
> tr '\0' '\n' < new_to_install.downgrade
> printf "exit code: %s\n" "$exit_code"
/tmp/dummy-package-1.0-1-any.pkg.tar.zst
exit code: 0

Build failure: exits with 1 when makepkg -fs fails

$ cd "$tmpdir"
> rm -f new_to_install.downgrade
> MAKEPKG_FAIL=1
> export -f su stat build_pkg
> export MAKEPKG_FAIL DOWNGRADE_ARCH
> bash -c 'cd "'"$tmpdir"'" && build_pkg "'"$tmpdir"'/dummy-package-1.0-g123456-any.gitpkg.tar.gz"'
[1]

$ test ! -f "$tmpdir/new_to_install.downgrade" && echo "file not created"
file not created

Non-git package: is written as-is

$ cd "$tmpdir"
> rm -f new_to_install.downgrade
> build_pkg "/cache/dummy-package-1.0-1-any.pkg.tar.zst"
> tr '\0' '\n' < new_to_install.downgrade
/cache/dummy-package-1.0-1-any.pkg.tar.zst