Skip to content

Commit

Permalink
Fix batch attachment deletion leaving empty directories (#25587)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Jun 27, 2023
1 parent 9caa047 commit 0ccf6c0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/lib/attachment_batch.rb
Expand Up @@ -64,7 +64,15 @@ def remove_files
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
Expand Down

0 comments on commit 0ccf6c0

Please sign in to comment.