From 046897f1c68036f1a1dc079254f5e98f25101c6e Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Wed, 17 Aug 2016 09:27:50 +0200 Subject: [PATCH] Rake task to clean up broken screenshots works now --- lib/tasks/remove_broken_screenshots.rake | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/tasks/remove_broken_screenshots.rake b/lib/tasks/remove_broken_screenshots.rake index 28b98ab..d7969ce 100644 --- a/lib/tasks/remove_broken_screenshots.rake +++ b/lib/tasks/remove_broken_screenshots.rake @@ -6,18 +6,16 @@ namespace :debshots do Rails.logger.level = Logger::INFO #Rails.logger.level = Logger::DEBUG - base_path = Rails.root.join('public') - Rails.logger.info "Iterating over screenshots" Screenshot.all.each do |screenshot| - path = File.join(base_path, screenshot.image_url(:large)) - Rails.logger.debug "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})" - # Check that the file actually exists - unless File.file? path - Rails.logger.error "Screenshots not found at #{path}. Removing." - next + path = screenshot.image.path(:large) + # Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})" + unless path and (File.file? path) + Rails.logger.info "Screenshot #{screenshot.id} image file not found at path '#{path}'. Removing." + screenshot.delete end end + Rails.logger.info "Done." end end \ No newline at end of file