mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FIX: ensure we remove tempfiles from disk when creating an upload
Follow-up to 46d12c5ad3
This commit is contained in:
parent
67787799bb
commit
9a81cb9e55
|
@ -143,7 +143,9 @@ class UploadCreator
|
|||
@upload
|
||||
end
|
||||
ensure
|
||||
@file&.close
|
||||
if @file
|
||||
@file.respond_to?(:close!) ? @file.close! : @file.close
|
||||
end
|
||||
end
|
||||
|
||||
def extract_image_info!
|
||||
|
@ -197,11 +199,11 @@ class UploadCreator
|
|||
keep_jpeg &&= (filesize - new_size) > MIN_CONVERT_TO_JPEG_BYTES_SAVED
|
||||
|
||||
if keep_jpeg
|
||||
@file.close
|
||||
@file.respond_to?(:close!) ? @file.close! : @file.close
|
||||
@file = jpeg_tempfile
|
||||
extract_image_info!
|
||||
else
|
||||
jpeg_tempfile&.close
|
||||
jpeg_tempfile.close!
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -230,16 +232,21 @@ class UploadCreator
|
|||
original_size = filesize
|
||||
down_tempfile = Tempfile.new(["down", ".#{@image_info.type}"])
|
||||
|
||||
from = @file.path
|
||||
to = down_tempfile.path
|
||||
|
||||
OptimizedImage.ensure_safe_paths!(from, to)
|
||||
|
||||
OptimizedImage.downsize(
|
||||
@file.path,
|
||||
down_tempfile.path,
|
||||
from,
|
||||
to,
|
||||
"50%",
|
||||
filename: @filename,
|
||||
allow_animation: allow_animation,
|
||||
raise_on_error: true
|
||||
)
|
||||
|
||||
@file.close
|
||||
@file.respond_to?(:close!) ? @file.close! : @file.close
|
||||
@file = down_tempfile
|
||||
|
||||
extract_image_info!
|
||||
|
|
Loading…
Reference in New Issue
Block a user