From: Ansgar Burchardt Date: Tue, 11 Aug 2015 19:36:19 +0000 (+0200) Subject: Allow checking files given an open file handle. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=55a06f4c01fb48573bc39e00009d02a4c2d73054;hp=657eb8fa41d9aaf303330a0c0b2800d3ef68ef78;p=dak.git Allow checking files given an open file handle. --- 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)