Skip to content

Commit

Permalink
Close file in SanitizedFile#mime_magic_content_type
Browse files Browse the repository at this point in the history
Fixes bug where file handles are being left open. This was introduced in #1934
and #1936
  • Loading branch information
Owen Davies committed Jul 11, 2016
1 parent 6de95db commit f6d65dd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/carrierwave/sanitized_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ def existing_content_type
end

def mime_magic_content_type
MimeMagic.by_magic(File.open(path)).try(:type) if path
if path
File.open(path) do |file|
MimeMagic.by_magic(file).try(:type)
end
end
rescue Errno::ENOENT
nil
end
Expand Down

0 comments on commit f6d65dd

Please sign in to comment.