Skip to content

Commit

Permalink
Don't close IO object in UploadedFile#open if it's already closed
Browse files Browse the repository at this point in the history
It seems that the StringIO object (and maybe some other IO objects as
well) raise an "IOError: closed stream" when attempting to close them if
they were already closed on older Ruby versions (2.2 and below).
  • Loading branch information
janko committed May 8, 2018
1 parent ff5d4d3 commit c02a005
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/shrine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def mime_type
#
# uploaded_file.open { |io| io.read } # the IO is automatically closed
def open(*args)
@io.close if @io
@io.close if @io && !(@io.respond_to?(:closed?) && @io.closed?)
@io = storage.open(id, *args)

return @io unless block_given?
Expand Down

0 comments on commit c02a005

Please sign in to comment.