]> cat aescling's git repositories - mastodon.git/commitdiff
Fix "tootctl media remove-orphans" crashing on “Import” files (#13685)
authorThibG <thib@sitedethib.com>
Sat, 9 May 2020 19:06:55 +0000 (21:06 +0200)
committerGitHub <noreply@github.com>
Sat, 9 May 2020 19:06:55 +0000 (21:06 +0200)
* Fix "tootctl media remove-orphans" crashing on “Import” files

* Also remove empty directories when removing orphaned media

config/initializers/inflections.rb
lib/mastodon/media_cli.rb

index c65153b0a7a19d712a77666d346e53d72b81c59c..0667a542c149b8298a103639cc572c44e41bf719 100644 (file)
@@ -19,4 +19,6 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
   inflect.acronym 'ActivityStreams'
   inflect.acronym 'JsonLd'
   inflect.acronym 'NodeInfo'
+
+  inflect.singular 'data', 'data'
 end
index 424d65a5f4e3a641b9675296396347138ebde99e..50654444650b11d2300f041b42518bdafab7337c 100644 (file)
@@ -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