Hi Ashley,

The RightAWS upload streaming is probably designed to work with both
in-memory strings and file or other io resources, which may have
different ways of reporting how large they are.

RightAWS probably did not anticipate that .size would consume a
resource.

The file responds to lstat, but if it is not large enough, it then
falls through to the second test.  Normally this would be effectively
a no-op, because the file does not respond to size.  However, here it
now does, and it consumes the resource.  My fix says don't bother
checking size if you responded to lstat.

The clearest logic would be:
  if obj.responds_to(:foo)
    if obj.foo ...
      ...
    end
  elsif obj.responds_to(:bar)
    if obj.bar ...
      ...
    end
  end

 However this is verbose, so we cut corners as:
 if obj.responds_to(:foo) && obj.foo || obj.responds_to(:bar) &&
obj.bar

 end

This shortcut is present in a lot of places, including some places in
Merb that result in unnecessary deprecation warnings.

-Gary


On Jan 5, 2:56 am, Ashley Moran <[email protected]> wrote:
> On Dec 28, 2009, at 1:09 am, Gary Yngve wrote:
>
> > module Enumerable
> >  ...
> >  def size
> >    size = 0
> >    each { size += 1 }
> >    size
> >  end
> > end
>
> >      if (data.respond_to?(:lstat) && data.lstat.size >=
> > USE_100_CONTINUE_PUT_SIZE) ||
> >         (!data.respond_to?(:lstat) && data.respond_to?(:size)  &&
> > data.size >= USE_100_CONTINUE_PUT_SIZE)
> >        headers['expect'] = '100-continue'
> >      end
>
> > -Gary
>
> Hi Gary
>
> This one concerns me.  Can you explain why the `!data.respond_to?(:lstat)` 
> has the effect it does?
>
> Patching this will make it work, but this is clearly not the correct 
> solution.  I suspect the error is in RightAWS S3, by making assumptions about 
> what responding to :size means - but I haven't thought through it much.
>
> > (who seems to be the king of weird bugs lately)
>
> Thanks for taking the crown =)
>
> Ashley
>
> --http://www.patchspace.co.uk/http://www.linkedin.com/in/ashleymoran
-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.


Reply via email to