Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tootctl media remove-orphans choking on unknown files in storage #13765

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/tootctl
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions lib/mastodon/media_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def remove_orphans
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
Expand Down Expand Up @@ -127,6 +132,11 @@ def remove_orphans
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
Expand Down Expand Up @@ -246,6 +256,11 @@ def lookup(url)
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

Expand Down Expand Up @@ -294,6 +309,8 @@ def preload_records_from_mixed_objects(objects)
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

Expand Down