1
0
mirror of https://github.com/whippyshou/mastodon synced 2024-11-24 15:16:26 +09:00

Fix batch attachment deletion leaving empty directories (#25587)

This commit is contained in:
Claire 2023-06-27 09:36:11 +02:00 committed by GitHub
parent 9caa0475f8
commit 0ccf6c0eb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,7 +64,15 @@ class AttachmentBatch
keys << attachment.style_name_as_path(style) keys << attachment.style_name_as_path(style)
when :filesystem when :filesystem
logger.debug { "Deleting #{attachment.path(style)}" } logger.debug { "Deleting #{attachment.path(style)}" }
FileUtils.remove_file(attachment.path(style), true) path = attachment.path(style)
FileUtils.remove_file(path, true)
begin
FileUtils.rmdir(File.dirname(path), parents: true)
rescue Errno::EEXIST, Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR, Errno::EACCES
# Ignore failure to delete a directory, with the same ignored errors
# as Paperclip
end
when :fog when :fog
logger.debug { "Deleting #{attachment.path(style)}" } logger.debug { "Deleting #{attachment.path(style)}" }
attachment.directory.files.new(key: attachment.path(style)).destroy attachment.directory.files.new(key: attachment.path(style)).destroy