[PATCH v2] paccache: Support cleaning many thousands of candidates

Leonid Bloch lb.workbox at gmail.com
Tue Jun 2 05:27:58 UTC 2020


In situations when there are many thousands of candidates for deletion,
paccache returns an "Argument list too long" error at the freed space
calculation stage, because the expansion of the ${candidates[@]} array
becomes too long for Bash.

This commit fixes that problem, by getting the @SIZECMD@ arguments via
`printf '%s\0' "${candidates[@]}" | xargs -0`, similarly to what is done
for the (re)moving commands below.

Signed-off-by: Leonid Bloch <lb.workbox at gmail.com>
---
 src/paccache.sh.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/paccache.sh.in b/src/paccache.sh.in
index af901f4..1311fd7 100644
--- a/src/paccache.sh.in
+++ b/src/paccache.sh.in
@@ -391,7 +391,8 @@ candidates=("${candtemp[@]}")
 unset candtemp
 
 # do this before we destroy anything
-totalsaved=$(@SIZECMD@ "${candidates[@]}" | awk '{ sum += $1 } END { print sum }')
+totalsaved=$(printf '%s\0' "${candidates[@]}" | xargs -0 @SIZECMD@ |
+		awk '{ sum += $1 } END { print sum }')
 
 # Exit immediately if a pipeline returns non-zero.
 set -o errexit
-- 
2.26.2


More information about the pacman-contrib mailing list