From 3e1a71be6e63696dfe9792f123f24ece1da8116a Mon Sep 17 00:00:00 2001 From: Ken D'Ambrosio Date: Tue, 12 May 2026 12:17:40 +0000 Subject: Prune orphaned thumbnails when update.rb removes deleted files When a media file is deleted from disk, also delete its cached thumbnail from cache/thumbs/ so stale .th.jpg files don't accumulate. Co-Authored-By: Claude Sonnet 4.6 --- scripts/update.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'scripts/update.rb') diff --git a/scripts/update.rb b/scripts/update.rb index 8e4cdd5..9052341 100644 --- a/scripts/update.rb +++ b/scripts/update.rb @@ -44,11 +44,17 @@ def process_dir(dir) .select { |n| MEDIA_EXTS.include?(File.extname(n).downcase.delete_prefix('.')) } .sort - # Remove stale entries for deleted files + # Remove stale entries for deleted files and their cached thumbnails removed = data['files'].keys - current - if removed.any? - puts " Removing stale entries: #{removed.join(', ')}" - removed.each { |n| data['files'].delete(n) } + removed.each do |n| + data['files'].delete(n) + thumb = File.join(CACHE_ROOT, rel.empty? ? "#{n}.th.jpg" : "#{rel}/#{n}.th.jpg") + if File.exist?(thumb) + File.unlink(thumb) + puts " Removed: #{n} (+ thumb)" + else + puts " Removed: #{n}" + end end # Process each file -- cgit v1.2.3