[pacman-dev] [PATCH] contrib/paccache: misc cleanup and bugfix
Dave Reisner
d at falconindy.com
Wed Aug 3 00:52:14 EDT 2011
* add paccache to .gitignore
* change error verbiage when run as root
* delete sigs along with packages
* fix bug in diskspace calculations
Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
This should cover Allan and Dan's concerns, as well as addressing
a silly bug I found in counting diskspace saved.
contrib/paccache.in | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/contrib/paccache.in b/contrib/paccache.in
index 0bd0cf7..34ca06b 100755
--- a/contrib/paccache.in
+++ b/contrib/paccache.in
@@ -110,10 +110,11 @@ pkgfilter() {
size_to_human() {
awk -v size="$1" '
BEGIN {
- suffix[1] = "KiB"
- suffix[2] = "MiB"
- suffix[3] = "GiB"
- suffix[4] = "TiB"
+ suffix[1] = "B"
+ suffix[2] = "KiB"
+ suffix[3] = "MiB"
+ suffix[4] = "GiB"
+ suffix[5] = "TiB"
count = 1
while (size > 1024) {
@@ -142,7 +143,7 @@ runcmd() {
}
summarize() {
- local -i filecount=$#
+ local -i filecount=$1; shift
local seenarch= seen= arch= name=
local -r pkg_re='(.+)-[^-]+-[0-9]+-([^.]+)\.pkg.*'
@@ -204,7 +205,7 @@ EOF
}
if (( ! UID )); then
- error "Bad dog, no biscuit. You will be prompted for privilege escalation."
+ error "Do not run this script as root. You will be prompted for privilege escalation."
exit 42
fi
@@ -277,8 +278,19 @@ if (( ! ${#candidates[*]} )); then
exit 1
fi
+# grab this prior to signature scavenging
+pkgcount=${#candidates[*]}
+
+# copy the list, merging in any found sigs
+for cand in "${candidates[@]}"; do
+ candtemp+=("$cand")
+ [[ -f $cand.sig ]] && candtemp+=("$cand.sig")
+done
+candidates=("${candtemp[@]}")
+unset candtemp
+
# do this before we destroy anything
-totalsaved=$(@SIZECMD@ "${candidates[@]}" | awk '{ sum = $1 } END { print sum }')
+totalsaved=$(@SIZECMD@ "${candidates[@]}" | awk '{ sum += $1 } END { print sum }')
# crush. kill. destroy.
(( verbose )) && cmdopts+=(-v)
@@ -288,4 +300,4 @@ elif (( move )); then
runcmd mv "${cmdopts[@]}" "${candidates[@]}" "$movedir"
fi
-summarize "${candidates[@]}"
+summarize "$pkgcount" "${candidates[@]}"
--
1.7.6
More information about the pacman-dev
mailing list