Skip to content

Commit

Permalink
[Analyzer] Ensure tempfile is always closed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mth0158 committed Nov 25, 2024
1 parent 0ef64e4 commit 77491c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ def read_image
end

Tempfile.create(binmode: true) do |tempfile|
if image(tempfile).valid?
yield image(tempfile)
else
logger.info "Skipping image analysis because ImageMagick doesn't support the file"
{}
begin
if image(tempfile).valid?
yield image(tempfile)
else
logger.info "Skipping image analysis because ImageMagick doesn't support the file"
{}
end
ensure
tempfile.close
end
end
rescue MiniMagick::Error => error
Expand Down
14 changes: 9 additions & 5 deletions lib/active_storage_validations/analyzer/image_analyzer/vips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ def read_image
end

Tempfile.create(binmode: true) do |tempfile|
if image(tempfile)
yield image(tempfile)
else
logger.info "Skipping image analysis because Vips doesn't support the file"
{}
begin
if image(tempfile)
yield image(tempfile)
else
logger.info "Skipping image analysis because Vips doesn't support the file"
{}
end
ensure
tempfile.close
end
end
rescue ::Vips::Error => error
Expand Down

0 comments on commit 77491c6

Please sign in to comment.