Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Bug in /lib/s3/right_s3_interface.rb - files don't have 'size' method

7 views
Skip to first unread message

Jxtps

unread,
Jun 3, 2010, 6:03:04 PM6/3/10
to ruby-aws
There's a bug in http://github.com/appoxy/aws/blob/master/lib/s3/right_s3_interface.rb
around line 395 as of 6/3/2010. The code snippet:

def put(bucket, key, data=nil, headers={})
# On Windows, if someone opens a file in text mode, we must
reset it so
# to binary mode for streaming to work properly
if(data.respond_to?(:binmode))
data.binmode
end
if (data.respond_to?(:lstat) && data.lstat.size >=
USE_100_CONTINUE_PUT_SIZE) ||
(data.respond_to?(:size) && data.size >=
USE_100_CONTINUE_PUT_SIZE)
headers['expect'] = '100-continue'
end
req_hash = generate_rest_request('PUT',
headers.merge(:url=>"#{bucket}/#{CGI::escape key}", :data=>data,
'Content-
Length' => ((data && data.size) || 0).to_s))
request_info(req_hash, RightHttp2xxParser.new)
rescue
on_exception
end

uses two different methods for getting the size of the data - either
through lstat, or through size. Files don't have a size method (it's a
static in the class) so the addition of (data && data.size) breaks
upload of File instances.

Fixed code (read data_size only once and use it in both referenced
locations):

def put(bucket, key, data=nil, headers={})
# On Windows, if someone opens a file in text mode, we must
reset it so
# to binary mode for streaming to work properly
if(data.respond_to?(:binmode))
data.binmode
end
data_size = data.respond_to?(:lstat) ? data.lstat.size :
(data.respond_to?(:size) ? data.size : 0)
if (data_size >= USE_100_CONTINUE_PUT_SIZE)
headers['expect'] = '100-continue'
end
req_hash = generate_rest_request('PUT',
headers.merge(:url=>"#{bucket}/#{CGI::escape key}", :data=>data,
'Content-
Length' => data_size.to_s))
request_info(req_hash, RightHttp2xxParser.new)
rescue
on_exception
end


Workaround: Monkeypatch File to add a size method that calls
lstat.size.



Travis Reeder

unread,
Jun 4, 2010, 5:03:08 PM6/4/10
to ruby...@googlegroups.com
I see what you're saying, in the first part it's checking either data.lstat.size or data.size, but then in the Content-Length header, it uses data.size right?

Just committed.




--
You received this message because you are subscribed to the Google Groups "ruby-aws" group.
To post to this group, send email to ruby...@googlegroups.com.
To unsubscribe from this group, send email to ruby-aws+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby-aws?hl=en.


Reply all
Reply to author
Forward
0 new messages