X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/edc5e4b6645b9b983a85a892bf3d3ad1432a657d..4146cc481cec9847eb41d3e5ba7602b4f33d2096:/apps/workbench/app/controllers/collections_controller.rb diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb index 3606ef0c8a..3c6c9d7a85 100644 --- a/apps/workbench/app/controllers/collections_controller.rb +++ b/apps/workbench/app/controllers/collections_controller.rb @@ -324,18 +324,18 @@ class CollectionsController < ApplicationController env['ARVADOS_API_HOST_INSECURE'] = "true" if Rails.configuration.arvados_insecure_https bytesleft = @opts[:maxbytes].andand.to_i || 2**16 - IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"], - 'rb') do |io| - bytecount = 0 - while bytesleft > 0 && buf = io.read(bytesleft) - # shrink the bytesleft count, if we were given a - # maximum byte count to read - if @opts.include? :maxbytes - bytesleft = bytesleft - buf.length - end - yield buf + io = IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"], 'rb') + while bytesleft > 0 && (buf = io.read([bytesleft, 2**16].min)) != nil + # shrink the bytesleft count, if we were given a maximum byte + # count to read + if @opts.include? :maxbytes + bytesleft = bytesleft - buf.length end + yield buf end + io.close + # "If ios is opened by IO.popen, close sets $?." + # http://www.ruby-doc.org/core-2.1.3/IO.html#method-i-close Rails.logger.warn("#{@opts[:uuid]}/#{@opts[:file]}: #{$?}") if $? != 0 end end