fiv/tools/clean-up-thumbnail-cache.sh

16 lines
636 B
Bash
Raw Permalink Normal View History

2021-10-01 11:37:50 +02:00
#!/bin/sh -e
# Remove thumbnails with URIs pointing to at this moment non-existing files.
2022-06-10 01:16:14 +02:00
ninja pnginfo
2021-10-01 11:37:50 +02:00
pnginfo=$(pwd)/pnginfo cache_home=${XDG_CACHE_HOME:-$HOME/.cache}
for size in normal large x-large xx-large; do
cd "$cache_home/thumbnails/$size" 2>/dev/null || continue
find . -name '*.png' -print0 | PNGINFO_SKIP_TRAILING=1 xargs -0 "$pnginfo" \
| jq -r '.info.texts."Thumb::URI"' | grep '^file:///' \
2021-10-01 11:37:50 +02:00
| grep -v '^file:///run/media/[^/]*/NIKON/' \
| perl -MURI -MURI::Escape -MDigest::MD5 -lne \
'print Digest::MD5->new()->add($_)->hexdigest . ".png"
if !stat(uri_unescape(URI->new($_)->path))' \
| xargs rm
done