FIX: Error when trying to move the same file to tombstone.

If an optimized image is destroyed when a previous similar optimized
image is already placed in the tombstone, `FileUtils.move` will blow up.
This commit is contained in:
Guo Xiang Tan 2019-04-24 16:44:32 +08:00
parent 01a3311ffb
commit 5b934cb33d

View File

@ -16,6 +16,7 @@ module FileStore
destination = "#{public_dir}#{url.sub("/uploads/", "/uploads/tombstone/")}"
dir = Pathname.new(destination).dirname
FileUtils.mkdir_p(dir) unless Dir.exists?(dir)
FileUtils.remove(destination) if File.exists?(destination)
FileUtils.move(source, destination, force: true)
FileUtils.touch(destination)
end