aboutsummaryrefslogtreecommitdiff
path: root/tools/clean-up-thumbnail-cache.sh
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-10-01 11:37:50 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-10-01 17:04:39 +0200
commit25871839a2885f5479bdd7efd2e78ca0aa1a7e09 (patch)
tree797e5837c3ed7c7304a3bf547b3b894bd6ed060e /tools/clean-up-thumbnail-cache.sh
parentbbabaabc200a63e3a2816378b2162536b9af43a5 (diff)
downloadfiv-25871839a2885f5479bdd7efd2e78ca0aa1a7e09.tar.gz
fiv-25871839a2885f5479bdd7efd2e78ca0aa1a7e09.tar.xz
fiv-25871839a2885f5479bdd7efd2e78ca0aa1a7e09.zip
Add thumbnail cache inspection tools
Diffstat (limited to 'tools/clean-up-thumbnail-cache.sh')
-rwxr-xr-xtools/clean-up-thumbnail-cache.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/clean-up-thumbnail-cache.sh b/tools/clean-up-thumbnail-cache.sh
new file mode 100755
index 0000000..490e317
--- /dev/null
+++ b/tools/clean-up-thumbnail-cache.sh
@@ -0,0 +1,15 @@
+#!/bin/sh -e
+# Remove thumbnails with URIs pointing to at this moment non-existing files.
+make pnginfo
+
+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://' \
+ | 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