From 34756cc4e095fa4d3add5ea94c1453e6a2f33064 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 9 May 2020 21:06:55 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20"tootctl=20media=20remove-orphans"=20cras?= =?UTF-8?q?hing=20on=20=E2=80=9CImport=E2=80=9D=20files=20(#13685)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix "tootctl media remove-orphans" crashing on “Import” files * Also remove empty directories when removing orphaned media --- config/initializers/inflections.rb | 2 ++ lib/mastodon/media_cli.rb | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index c65153b0a7a..0667a542c14 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 424d65a5f4e..50654444650 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