diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2017-05-05 13:12:32 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@parabola.nu> | 2017-05-05 18:31:18 -0400 |
commit | cf53710b94a4b1c6bb10d6d05a6a3a83e5610d13 (patch) | |
tree | feaa15ebcd4874be6dff066ffa83fffbb9bae150 /lib | |
parent | dd21fbf3c7cdbd77e2d1fa11b1153d55ccb0292a (diff) | |
download | devtools32-cf53710b94a4b1c6bb10d6d05a6a3a83e5610d13.tar.xz |
common.sh: Add a find_cached_srcpackage counterpart to find_cached_package
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common.sh | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/common.sh b/lib/common.sh index ed98449..118a06c 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -281,3 +281,60 @@ 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. +## +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 +} |