]> git.decadent.org.uk Git - dak.git/commitdiff
Allow checking files given an open file handle.
authorAnsgar Burchardt <ansgar@debian.org>
Tue, 11 Aug 2015 19:36:19 +0000 (21:36 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Wed, 12 Aug 2015 07:59:43 +0000 (09:59 +0200)
daklib/upload.py

index 8ab532c23eef1b5825e48e08383580ff389e370f..b5a5f4f27e6ab33ea12dbe620998ce1a23e09263 100644 (file)
@@ -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)