From ff78b84e4deb64014b3032f653088a5875b243bd Mon Sep 17 00:00:00 2001 From: DC1TC <128843042+DC1TC@users.noreply.github.com> Date: Wed, 13 May 2026 21:33:32 +0200 Subject: [PATCH] Fix E2BIG error in optimize.sh caused by too many arguments Instead of passing the full list of images once, use smaller batches of images paths passed to sharp-cli. --- optimize.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/optimize.sh b/optimize.sh index e61b27a5..0662c738 100755 --- a/optimize.sh +++ b/optimize.sh @@ -1,3 +1,28 @@ #!/bin/bash +set -euo pipefail echo "running image optimization" -npx --yes sharp-cli resize 1200 --withoutEnlargement true --optimise true --progressive true --withMetadata false --failOn none --input $(find ./docs \( -name cache -prune \) -o -name '*' -type f -exec file {} \; | awk -F: '{ if ($2 ~/[Ii]mage|EPS/) print $1}') --output "{dir}/{base}" + +ROOT_DIR="./docs" +BATCH_SIZE=73 + +# Build a list of image files (skip "cache" directories) +file_list=$(mktemp) +find "$ROOT_DIR" \( -name cache -prune \) -o -type f -exec file {} \; \ + | awk -F: '{ if ($2 ~ /[Ii]mage|EPS/) print $1 }' > "$file_list" + +# Process in batches using xargs; each invocation gets up to $BATCH_SIZE files +sparp_cli_cmd() { + local batch_args=("$@") + npx --yes sharp-cli resize 1200 \ + --withoutEnlargement true --optimise true --progressive true --withMetadata false --failOn none \ + --input "${batch_args[@]}" --output "{dir}/{base}" +} + +export -f sparp_cli_cmd + +# Use xargs to call a shell wrapper which forwards the args into xargs_cmd +# The "_" is the placeholder $0 so filenames become $1..$N inside the wrapper +xargs -r -n "$BATCH_SIZE" bash -c 'sparp_cli_cmd "$@"' _ < "$file_list" + +# Cleanup +rm -f "$file_list" \ No newline at end of file