Sort ZIPs by size descending before processing

This commit is contained in:
2026-07-04 22:45:06 -04:00
parent 8670eb372f
commit 03d268ac89
2 changed files with 28 additions and 4 deletions
+23
View File
@@ -53,6 +53,29 @@ teardown() {
assert_equal "$(grep -c 'Resized' <<<"$output")" "2"
}
@test "processes ZIPs in descending size order" {
# Create ZIPs of different sizes by varying image dimensions
local small medium large
small="$TEST_WORKDIR/small.zip"
medium="$TEST_WORKDIR/medium.zip"
large="$TEST_WORKDIR/large.zip"
convert -size 50x50 xc:gray "$TEST_WORKDIR/s.jpg"
convert -size 100x100 xc:gray "$TEST_WORKDIR/m.jpg"
convert -size 200x200 xc:gray "$TEST_WORKDIR/l.jpg"
(cd "$TEST_WORKDIR" && zip -q small.zip s.jpg)
(cd "$TEST_WORKDIR" && zip -q medium.zip m.jpg)
(cd "$TEST_WORKDIR" && zip -q large.zip l.jpg)
run "$SCRIPT" "$TEST_WORKDIR"
assert_success
# Extract the order ZIPs were processed from the output
local order
order=$(grep 'Processing file' <<<"$output" | grep -o '[a-z]*.zip' | tr '\n' ' ')
assert_equal "$order" "large.zip medium.zip small.zip "
}
@test "no temp files left in /dev/shm after recursive run" {
make_zip "$TEST_WORKDIR/a.zip" "$FIXTURES/unprocessed.jpg"
make_zip "$TEST_WORKDIR/b.zip" "$FIXTURES/processed.jpg"
+4 -3
View File
@@ -10,8 +10,9 @@ fi
echo "Resizing images in ZIPs recursively in $SEARCH_DIR"
find "$SEARCH_DIR" -iname '*.zip' -print0 | while IFS= read -r -d '' f
do
find "$SEARCH_DIR" -iname '*.zip' -printf '%s\t%p\0' | \
sort -z -t$'\t' -k1,1rn | \
while IFS=$'\t' read -r -d '' _size f; do
"$SCRIPT_DIR/zip_images_resize.sh" "$f"
done
done