diff options
| author | Ken D'Ambrosio <ken@jots.org> | 2026-05-12 12:17:40 +0000 |
|---|---|---|
| committer | Ken D'Ambrosio <ken@jots.org> | 2026-05-12 12:17:40 +0000 |
| commit | 3e1a71be6e63696dfe9792f123f24ece1da8116a (patch) | |
| tree | 4678ff7c4b55d19e312a58ddbb0d5d34af6eb4df /scripts | |
| parent | a06f0f9b22e0eed2328fb4062b75dd19c7a2c65f (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/update.rb | 14 |
1 files changed, 10 insertions, 4 deletions
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 |
