From 34756cc4e095fa4d3add5ea94c1453e6a2f33064 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 9 May 2020 21:06:55 +0200 Subject: Fix "tootctl media remove-orphans" crashing on “Import” files (#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 --- lib/mastodon/media_cli.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') 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 -- cgit