From 55a06f4c01fb48573bc39e00009d02a4c2d73054 Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Tue, 11 Aug 2015 21:36:19 +0200 Subject: [PATCH] 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 8ab532c2..b5a5f4f2 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.39.2