Skip to content

Commit

Permalink
Fix "tootctl media remove-orphans" crashing on “Import” files (#13685)
Browse files Browse the repository at this point in the history
* Fix "tootctl media remove-orphans" crashing on “Import” files

* Also remove empty directories when removing orphaned media
  • Loading branch information
ClearlyClaire authored May 9, 2020
1 parent 38b6951 commit 34756cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
inflect.acronym 'ActivityStreams'
inflect.acronym 'JsonLd'
inflect.acronym 'NodeInfo'

inflect.singular 'data', 'data'
end
9 changes: 8 additions & 1 deletion lib/mastodon/media_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ def remove_orphans
begin
size = File.size(path)

File.delete(path) unless options[:dry_run]
unless options[:dry_run]
File.delete(path)
begin
FileUtils.rmdir(File.dirname(path), parents: true)
rescue Errno::ENOTEMPTY
# OK
end
end

reclaimed_bytes += size
removed += 1
Expand Down

0 comments on commit 34756cc

Please sign in to comment.