From 927f9ea4997676bcceea0d625703ac6ec66a68b2 Mon Sep 17 00:00:00 2001 From: ThibG Date: Fri, 15 May 2020 11:38:12 +0200 Subject: Fix GifReader exceptions (#13760) --- lib/paperclip/gif_transcoder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/paperclip/gif_transcoder.rb b/lib/paperclip/gif_transcoder.rb index 64f12f963..9f3c8e8be 100644 --- a/lib/paperclip/gif_transcoder.rb +++ b/lib/paperclip/gif_transcoder.rb @@ -6,7 +6,7 @@ class GifReader EXTENSION_LABELS = [0xf9, 0x01, 0xff].freeze GIF_HEADERS = %w(GIF87a GIF89a).freeze - class GifReaderException; end + class GifReaderException < StandardError; end class UnknownImageType < GifReaderException; end -- cgit From 2b91a3dac0a71108042481d27f549c2261e5de41 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 15 May 2020 17:15:24 +0200 Subject: Fix `tootctl upgrade storage-schema` misbehaving (#13761) - Fix not moving original files of custom emojis - Fix command failing to move any files with S3 storage - Fix command marking records as upgraded when move failed Fix #13594 --- lib/mastodon/upgrade_cli.rb | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/mastodon/upgrade_cli.rb b/lib/mastodon/upgrade_cli.rb index 779462a4f..629834b19 100644 --- a/lib/mastodon/upgrade_cli.rb +++ b/lib/mastodon/upgrade_cli.rb @@ -41,23 +41,32 @@ module Mastodon klass.find_each do |record| attachment_names.each do |attachment_name| attachment = record.public_send(attachment_name) + upgraded = false next if attachment.blank? || attachment.storage_schema_version >= CURRENT_STORAGE_SCHEMA_VERSION - attachment.styles.each_key do |style| - case Paperclip::Attachment.default_options[:storage] - when :s3 - upgrade_storage_s3(progress, attachment, style) - when :fog - upgrade_storage_fog(progress, attachment, style) - when :filesystem - upgrade_storage_filesystem(progress, attachment, style) + styles = attachment.styles.keys + + styles << :original unless styles.include?(:original) + + styles.each do |style| + success = begin + case Paperclip::Attachment.default_options[:storage] + when :s3 + upgrade_storage_s3(progress, attachment, style) + when :fog + upgrade_storage_fog(progress, attachment, style) + when :filesystem + upgrade_storage_filesystem(progress, attachment, style) + end end + upgraded = true if style == :original && success + progress.increment end - attachment.instance_write(:storage_schema_version, CURRENT_STORAGE_SCHEMA_VERSION) + attachment.instance_write(:storage_schema_version, CURRENT_STORAGE_SCHEMA_VERSION) if upgraded end if record.changed? @@ -78,18 +87,20 @@ module Mastodon def upgrade_storage_s3(progress, attachment, style) previous_storage_schema_version = attachment.storage_schema_version object = attachment.s3_object(style) + success = true attachment.instance_write(:storage_schema_version, CURRENT_STORAGE_SCHEMA_VERSION) - upgraded_path = attachment.path(style) + new_object = attachment.s3_object(style) - if upgraded_path != object.key && object.exists? - progress.log("Moving #{object.key} to #{upgraded_path}") if options[:verbose] + if new_object.key != object.key && object.exists? + progress.log("Moving #{object.key} to #{new_object.key}") if options[:verbose] begin - object.move_to(upgraded_path) unless dry_run? + object.move_to(new_object) unless dry_run? rescue => e progress.log(pastel.red("Error processing #{object.key}: #{e}")) + success = false end end @@ -97,6 +108,7 @@ module Mastodon # previous version at the end. The upgrade will be recorded after # all styles are updated attachment.instance_write(:storage_schema_version, previous_storage_schema_version) + success end def upgrade_storage_fog(_progress, _attachment, _style) @@ -107,6 +119,7 @@ module Mastodon def upgrade_storage_filesystem(progress, attachment, style) previous_storage_schema_version = attachment.storage_schema_version previous_path = attachment.path(style) + success = true attachment.instance_write(:storage_schema_version, CURRENT_STORAGE_SCHEMA_VERSION) @@ -128,6 +141,7 @@ module Mastodon end rescue => e progress.log(pastel.red("Error processing #{previous_path}: #{e}")) + success = false unless dry_run? begin @@ -143,6 +157,7 @@ module Mastodon # previous version at the end. The upgrade will be recorded after # all styles are updated attachment.instance_write(:storage_schema_version, previous_storage_schema_version) + success end end end -- cgit From 199bbbcb9fe0620000538ae0c7766ff4a8f4cf0c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 15 May 2020 18:41:27 +0200 Subject: Fix `tootctl media remove-orphans` choking on unknown files in storage (#13765) Fix #13762 Catch tootctl interrupt to prevent confusing stacktrace --- bin/tootctl | 8 +++++++- lib/mastodon/media_cli.rb | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/bin/tootctl b/bin/tootctl index f26e1c7ed..a9ebb22c6 100755 --- a/bin/tootctl +++ b/bin/tootctl @@ -1,5 +1,11 @@ #!/usr/bin/env ruby APP_PATH = File.expand_path('../config/application', __dir__) + require_relative '../config/boot' require_relative '../lib/cli' -Mastodon::CLI.start(ARGV) + +begin + Mastodon::CLI.start(ARGV) +rescue Interrupt + exit(130) +end diff --git a/lib/mastodon/media_cli.rb b/lib/mastodon/media_cli.rb index 2b1653335..c95f3410a 100644 --- a/lib/mastodon/media_cli.rb +++ b/lib/mastodon/media_cli.rb @@ -88,6 +88,11 @@ module Mastodon path_segments = object.key.split('/') path_segments.delete('cache') + if path_segments.size != 7 + progress.log(pastel.yellow("Unrecognized file found: #{object.key}")) + next + end + model_name = path_segments.first.classify attachment_name = path_segments[1].singularize record_id = path_segments[2..-2].join.to_i @@ -127,6 +132,11 @@ module Mastodon path_segments = key.split(File::SEPARATOR) path_segments.delete('cache') + if path_segments.size != 7 + progress.log(pastel.yellow("Unrecognized file found: #{key}")) + next + end + model_name = path_segments.first.classify record_id = path_segments[2..-2].join.to_i attachment_name = path_segments[1].singularize @@ -246,6 +256,11 @@ module Mastodon path_segments = path.split('/')[2..-1] path_segments.delete('cache') + if path_segments.size != 7 + say('Not a media URL', :red) + exit(1) + end + model_name = path_segments.first.classify record_id = path_segments[2..-2].join.to_i @@ -294,6 +309,8 @@ module Mastodon segments = object.key.split('/') segments.delete('cache') + next if segments.size != 7 + model_name = segments.first.classify record_id = segments[2..-2].join.to_i -- cgit From ce87469d0a085b238646387fb01d78c206b83124 Mon Sep 17 00:00:00 2001 From: Stanislas Date: Sun, 17 May 2020 17:27:36 +0200 Subject: Fix `tootctl upgrade storage-schema` S3 ACL (#13768) --- lib/mastodon/upgrade_cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mastodon/upgrade_cli.rb b/lib/mastodon/upgrade_cli.rb index 629834b19..570b7e6fa 100644 --- a/lib/mastodon/upgrade_cli.rb +++ b/lib/mastodon/upgrade_cli.rb @@ -97,7 +97,7 @@ module Mastodon progress.log("Moving #{object.key} to #{new_object.key}") if options[:verbose] begin - object.move_to(new_object) unless dry_run? + object.move_to(new_object, acl: attachment.s3_permissions(style)) unless dry_run? rescue => e progress.log(pastel.red("Error processing #{object.key}: #{e}")) success = false -- cgit