Fix #3235: Replacements deleting files currently in use.

This commit is contained in:
evazion
2017-07-24 23:04:01 -05:00
parent 11ef460db0
commit b53371b698
2 changed files with 25 additions and 2 deletions

View File

@@ -67,9 +67,11 @@ class Post < ApplicationRecord
module ClassMethods
def delete_files(post_id, file_path, large_file_path, preview_file_path, force: false)
unless force
post = Post.find(post_id)
# XXX should pass in the md5 instead of parsing it.
preview_file_path =~ %r!/data/preview/(?:test\.)?([a-z0-9]{32})\.jpg\z!
md5 = $1
if post.file_path == file_path || post.large_file_path == large_file_path || post.preview_file_path == preview_file_path
if Post.where(md5: md5).exists?
raise DeletionError.new("Files still in use; skipping deletion.")
end
end