Fix batch attachment deletion leaving empty directories (#25587)

lolsob-rspec
Claire 2023-06-27 09:36:11 +02:00 committed by GitHub
parent ee350f0491
commit 1569b36e28
1 changed files with 9 additions and 1 deletions

View File

@ -64,7 +64,15 @@ class AttachmentBatch
keys << attachment.style_name_as_path(style)
when :filesystem
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
logger.debug { "Deleting #{attachment.path(style)}" }
attachment.directory.files.new(key: attachment.path(style)).destroy