about summary refs log tree commit diff
path: root/lib/mastodon
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 /lib/mastodon
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
Diffstat (limited to 'lib/mastodon')
-rw-r--r--lib/mastodon/media_cli.rb9
1 files changed, 8 insertions, 1 deletions
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