From 27441f201c2394a991427f6a47199dd40024497b Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 20 Oct 2013 16:17:45 -0400 Subject: common: implement find_cached_package This function (currently) searches through $PWD and $PKGDEST looking for a tarball matching the requested package name, architecture, and pkgver. If found, it writes the full path to the located package to stdout and returns 0, else 1. If more than 1 match is found, it's treated as an error and the user will need to figure out what to do. Use this in checkpkg and commitpkg, which previously implemented their own less complete logic, to locate the build artifacts they rely on. Signed-off-by: Dave Reisner Signed-off-by: Pierre Schmitz --- lib/common.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index 3ec26ff..1812cb7 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1,6 +1,8 @@ # Avoid any encoding problems export LANG=C +shopt -s extglob + # check if messages are to be printed using color unset ALL_OFF BOLD BLUE GREEN RED YELLOW if [[ -t 2 ]]; then @@ -154,3 +156,70 @@ slock() { stat_done fi } + +## +# usage: pkgver_equal( $pkgver1, $pkgver2 ) +## +pkgver_equal() { + local left right + + if [[ $1 = *-* && $2 = *-* ]]; then + # if both versions have a pkgrel, then they must be an exact match + [[ $1 = "$2" ]] + else + # otherwise, trim any pkgrel and compare the bare version. + [[ ${1%%-*} = "${2%%-*}" ]] + fi +} + +## +# usage: find_cached_package( $pkgname, $pkgver, $arch ) +# +# $pkgver can be supplied with or without a pkgrel appended. +# If not supplied, any pkgrel will be matched. +## +find_cached_package() { + local searchdirs=("$PWD" "$PKGDEST") results=() + local targetname=$1 targetver=$2 targetarch=$3 + local dir pkg pkgbasename pkgparts name ver rel arch size results + + for dir in "${searchdirs[@]}"; do + [[ -d $dir ]] || continue + + for pkg in "$dir"/*.pkg.tar?(.?z); do + [[ -f $pkg ]] || continue + + # split apart package filename into parts + pkgbasename=${pkg##*/} + pkgbasename=${pkgbasename%.pkg.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" + return 0 + ;; + *) + error 'Multiple packages found:' + printf '\t%s\n' "${results[@]}" + return 1 + esac +} -- cgit v1.2.3 From 1e043445d2fc264efa73089086f6a769183ad52b Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 3 Nov 2013 18:57:07 -0500 Subject: find_cached_package: avoid adding duplicates If PKGDEST is set when makepkg was run, the package will be present in find_cached_package's search path by default, causing an error. This also fixes a display bug which causes no output to be shown when multiple packages are found. Fixes FS#37626. Signed-off-by: Dave Reisner Signed-off-by: Pierre Schmitz --- lib/common.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index 1812cb7..cb9db76 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -181,7 +181,7 @@ pkgver_equal() { find_cached_package() { local searchdirs=("$PWD" "$PKGDEST") results=() local targetname=$1 targetver=$2 targetarch=$3 - local dir pkg pkgbasename pkgparts name ver rel arch size results + local dir pkg pkgbasename pkgparts name ver rel arch size r results for dir in "${searchdirs[@]}"; do [[ -d $dir ]] || continue @@ -189,6 +189,11 @@ find_cached_package() { for pkg in "$dir"/*.pkg.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%.pkg.tar?(.?z)} @@ -219,7 +224,7 @@ find_cached_package() { ;; *) error 'Multiple packages found:' - printf '\t%s\n' "${results[@]}" + printf '\t%s\n' "${results[@]}" >&2 return 1 esac } -- cgit v1.2.3