[pacman-dev] [PATCH 1/6] bacman: get local package db path the correct way
lolilolicon
lolilolicon at gmail.com
Thu Sep 29 13:14:01 EDT 2011
Use globbing and store the expansion results in an array.
The [epoch:]pkgver part can start without an integer, e.g. lshw is
currently at version B.02.15.
extglob is just good enough to match pkgname-[epoch:]pkgver-pkgrel.
Set nullglob globally.
Signed-off-by: lolilolicon <lolilolicon at gmail.com>
---
contrib/bacman.in | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/contrib/bacman.in b/contrib/bacman.in
index fe13e5b..b51a4a3 100755
--- a/contrib/bacman.in
+++ b/contrib/bacman.in
@@ -23,6 +23,9 @@
readonly progname="bacman"
readonly progver="0.2.1"
+shopt -s extglob
+shopt -s nullglob
+
#
# User Friendliness
#
@@ -90,8 +93,7 @@ pkg_dest="${PKGDEST:-$PWD}"
pkg_pkger=${PACKAGER:-'Unknown Packager'}
pkg_name="$1"
-pkg_dir="$(echo $pac_db/$pkg_name-[0-9]*)"
-pkg_namver="${pkg_dir##*/}"
+pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([0-9]))
#
# Checks everything is in place
@@ -101,7 +103,11 @@ if [ ! -d "$pac_db" ] ; then
exit 1
fi
-if [ ! -d "$pkg_dir" ] ; then
+if [ ${#pkg_dir[@]} -gt 1 ]; then
+ echo "ERROR: ${#pkg_dir[@]} entries for package ${pkg_name} found in pacman database"
+ printf "%s\n" "${pkg_dir[@]}"
+ exit 1
+elif [ ${#pkg_dir[@]} -eq 0 -o ! -d "$pkg_dir" ]; then
echo "ERROR: package ${pkg_name} not found in pacman database"
exit 1
fi
@@ -109,6 +115,7 @@ fi
#
# Begin
#
+pkg_namver="${pkg_dir##*/}"
echo Package: ${pkg_namver}
work_dir=$(mktemp -d -p /tmp)
cd "$work_dir" || exit 1
@@ -275,9 +282,6 @@ esac
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
-# when fileglobbing, we want * in an empty directory to expand to
-# the null string rather than itself
-shopt -s nullglob
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
bsdtar -cf - $comp_files * |
--
1.7.6.4
More information about the pacman-dev
mailing list