about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-11 15:44:03 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-11 15:44:03 -0800
commitec22a960d443ea846161fc16c78f5a6c4206f95b (patch)
treeef879c982fd74c0abc38cdd8528d46f336e50ccf
parenta3977a51ae30fd2856c969e2e7897535715d19c6 (diff)
downloadupr-ec22a960d443ea846161fc16c78f5a6c4206f95b.tar.gz
input_wrapper: use the new finish methods in backends
This provides the ability to add notifications when
we finish an upload
-rw-r--r--lib/upr/input_wrapper.rb13
1 files 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