about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-05-09 21:06:55 +0200
committerGitHub <noreply@github.com>2020-05-09 21:06:55 +0200
commit34756cc4e095fa4d3add5ea94c1453e6a2f33064 (patch)
tree7f2dfb522b0b20709e0518c26a7e64d05332cf12
parent38b69512ffd13abc992a91e33e199881d38bc164 (diff)
Fix "tootctl media remove-orphans" crashing on “Import” files (#13685)
* Fix "tootctl media remove-orphans" crashing on “Import” files

* Also remove empty directories when removing orphaned media
-rw-r--r--config/initializers/inflections.rb2
-rw-r--r--lib/mastodon/media_cli.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
index c65153b0a..0667a542c 100644
--- a/config/initializers/inflections.rb
+++ b/config/initializers/inflections.rb
@@ -19,4 +19,6 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
   inflect.acronym 'ActivityStreams'
   inflect.acronym 'JsonLd'
   inflect.acronym 'NodeInfo'
+
+  inflect.singular 'data', 'data'
 end
diff --git a/lib/mastodon/media_cli.rb b/lib/mastodon/media_cli.rb
index 424d65a5f..506544446 100644
--- a/lib/mastodon/media_cli.rb
+++ b/lib/mastodon/media_cli.rb
@@ -144,7 +144,14 @@ module Mastodon
           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