data = grabber.urlread(filename)
- # XXX check the hashsum of the downloaded file
+ # check the hashsum of the downloaded file
+ if not util.calc_hash1(data=data) == self.metadata.database_hash1:
+ # XXX an exception is not a very good idea because this file could
+ # be downloaded from another mirror. need a better way to handle this.
+ raise Exception, "Downloaded file did not match the hashsum. Need to re-download it."
with cache.open(filename, "w") as o:
o.write(data)
self._update_database(force)
# XXX this code needs lots of work:
- # XXX * make checks for downloads (hashsums)
# XXX * check the metadata content
def save(self, path=None, compress="xz"):
return "%d%s" % (int(s), units[unit])
-def calc_hash1(filename):
+def calc_hash1(filename=None, data=None):
h = hashlib.sha1()
- f = open(filename)
- buf = f.read(BUFFER_SIZE)
- while buf:
- h.update(buf)
+ if filename:
+ f = open(filename)
buf = f.read(BUFFER_SIZE)
+ while buf:
+ h.update(buf)
+ buf = f.read(BUFFER_SIZE)
+
+ f.close()
+
+ elif data:
+ h.update(data)
- f.close()
return h.hexdigest()
def parse_pkg_expr(s):