[v2] paccache: Support cleaning many thousands of candidates

Message ID 20200602052758.4817-1-lb.workbox@gmail.com
State Accepted, archived
Headers show
Series [v2] paccache: Support cleaning many thousands of candidates | expand

Commit Message

Leonid Bloch June 2, 2020, 5:27 a.m. UTC
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@gmail.com>
---
 src/paccache.sh.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Daniel M. Capella July 28, 2020, 4:55 a.m. UTC | #1
On June 2, 2020 1:27:58 AM EDT, Leonid Bloch <lb.workbox@gmail.com> wrote:
> 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@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

Merged, sorry for the wait.

--
Best,
Daniel <https://danielcapella.com>

Patch

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