diff --git a/lib/tasks/remove_broken_screenshots.rake b/lib/tasks/remove_broken_screenshots.rake new file mode 100644 index 0000000..28b98ab --- /dev/null +++ b/lib/tasks/remove_broken_screenshots.rake @@ -0,0 +1,23 @@ +namespace :debshots do + desc "Remove screenshot objects with non-existing images" + + task :remove_broken_screenshots => :environment do + Rails.logger = Logger.new(STDOUT) + 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 + end + end + end +end \ No newline at end of file