[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Allow checking files given an open file handle.



---
 daklib/upload.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/daklib/upload.py b/daklib/upload.py
index 8ab532c..b5a5f4f 100644
--- a/daklib/upload.py
+++ b/daklib/upload.py
@@ -147,16 +147,19 @@ class HashedFile(object):
         @raise InvalidHashException: hash mismatch
         """
         path = os.path.join(directory, self.filename)
-
         try:
             with open(path) as fh:
-                size = os.fstat(fh.fileno()).st_size
-                hashes = apt_pkg.Hashes(fh)
+                self.check_fh(fh)
         except IOError as e:
             if e.errno == errno.ENOENT:
                 raise FileDoesNotExist(self.filename)
             raise
 
+    def check_fh(self, fh):
+        size = os.fstat(fh.fileno()).st_size
+        fh.seek(0)
+        hashes = apt_pkg.Hashes(fh)
+
         if size != self.size:
             raise InvalidHashException(self.filename, 'size', self.size, size)
 
-- 
2.1.4



Reply to: