index : devtools32 | |
Archlinux32 fork of devtools | gitolite user |
summaryrefslogtreecommitdiff |
author | Luke Shumaker <lukeshu@parabola.nu> | 2017-05-05 13:12:32 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@parabola.nu> | 2018-08-04 12:57:37 -0400 |
commit | f4dcf19865739b5f3e1072894f2123b5af7113aa (patch) | |
tree | c7538e56cd7d24ec5099b88f588aa5f222766427 /lib/common.sh | |
parent | 1a9c7c81b558b0fd44571371b482c4017d1e0cce (diff) |
-rw-r--r-- | lib/common.sh | 60 |
diff --git a/lib/common.sh b/lib/common.sh index 0b1dc59..d5292ca 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -224,3 +224,63 @@ find_cached_package() { return 1 esac } + +## +# usage: find_cached_srcpackage( $pkgname, $pkgver, $arch ) +# +# $pkgver can be supplied with or without a pkgrel appended. +# If not supplied, any pkgrel will be matched. +# +# Note that this expects $arch to be in the filename, which makepkg +# --[all]source doesn't normally do. +## +find_cached_srcpackage() { + local searchdirs=("$PWD" "$SRCPKGDEST") results=() + local targetname=$1 targetver=$2 targetarch=$3 + local dir pkg pkgbasename name ver rel arch r results + + for dir in "${searchdirs[@]}"; do + [[ -d $dir ]] || continue + + for pkg in "$dir"/*.src.tar?(.?z); do + [[ -f $pkg ]] || continue + + # avoid adding duplicates of the same inode + for r in "${results[@]}"; do + [[ $r -ef $pkg ]] && continue 2 + done + + # split apart package filename into parts + pkgbasename=${pkg##*/} + pkgbasename=${pkgbasename%.src.tar?(.?z)} + + arch=${pkgbasename##*-} + pkgbasename=${pkgbasename%-"$arch"} + + rel=${pkgbasename##*-} + pkgbasename=${pkgbasename%-"$rel"} + + ver=${pkgbasename##*-} + name=${pkgbasename%-"$ver"} + + if [[ $targetname = "$name" && $targetarch = "$arch" ]] && + pkgver_equal "$targetver" "$ver-$rel"; then + results+=("$pkg") + fi + done + done + + case ${#results[*]} in + 0) + return 1 + ;; + 1) + printf '%s\n' "${results[0]}" + return 0 + ;; + *) + _l error 'Multiple packages found:' + printf '\t%s\n' "${results[@]}" >&2 + return 1 + esac +} |