From ec22a960d443ea846161fc16c78f5a6c4206f95b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 11 Nov 2009 15:44:03 -0800 Subject: [PATCH] input_wrapper: use the new finish methods in backends This provides the ability to add notifications when we finish an upload --- lib/upr/input_wrapper.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/upr/input_wrapper.rb b/lib/upr/input_wrapper.rb index d267926..2070d38 100644 --- a/lib/upr/input_wrapper.rb +++ b/lib/upr/input_wrapper.rb @@ -64,6 +64,7 @@ module Upr def _incr(nr) self.pos += nr + _finish if content_length && pos >= content_length if (nr = pos - seen) > 0 && mtime <= (Time.now.to_i - frequency) backend.incr(upload_id, nr) self.seen = pos @@ -71,13 +72,18 @@ module Upr end end + def _finish + self.seen = backend.finish(upload_id).seen + self.content_length ||= self.seen + end + def size rv = input.size # we had an unknown length and just had to read in everything to get it if content_length.nil? _incr(rv - seen) - self.content_length = rv + _finish end rv end @@ -89,13 +95,13 @@ module Upr def gets rv = input.gets - _incr(rv.size) unless rv.nil? + rv.nil? ? _finish : _incr(rv.size) rv end def read(*args) rv = input.read(*args) - _incr(rv.size) unless rv.nil? + rv.nil? || rv.size == 0 ? _finish : _incr(rv.size) rv end @@ -104,6 +110,7 @@ module Upr _incr(chunk.size) yield chunk end + _finish end end -- 2.11.4.GIT