def verify(self, signature, cleartext):
assert signature, "Empty signature?"
+ assert signature, "Signature is empty?"
+
signature = io.BytesIO(signature)
cleartext = io.BytesIO(cleartext)
return open(filename, *args, **kwargs)
+ def hash1(self, filename):
+ """
+ Return hash of the file in the cache.
+ """
+ return util.calc_hash1(self.abspath(filename))
+
def verify(self, filename, hash1):
"""
Return a bool that indicates if a file matches the given hash.
"""
- return util.calc_hash1(self.abspath(filename)) == hash1
+ return self.hash1(filename) == hash1
def remove(self, filename):
"""
download = False
else:
# The file in cache has a wrong hash. Remove it and repeat download.
- cache.remove(cache_filename)
+ self.cache.remove(cache_filename)
# Get a package grabber and add mirror download capabilities to it.
grabber = downloader.PackageDownloader(
raise OfflineModeError, _("Cannot download this file in offline mode: %s") \
% filename
- i = grabber.urlopen(filename)
+ try:
+ i = grabber.urlopen(filename)
+ except urlgrabber.grabber.URLGrabError, e:
+ raise DownloadError, _("Could not download %s: %s") % (filename, e)
# Open input and output files and download the file.
o = self.cache.open(cache_filename, "w")
i.close()
o.close()
- if self.cache.verify(cache_filename, hash1):
+ # Calc the hash1 of the downloaded file.
+ calc_hash1 = self.cache.hash1(cache_filename)
+
+ if calc_hash1 == hash1:
logger.debug("Successfully downloaded %s (%s)." % (filename, hash1))
break
+ sums = {
+ "good" : hash1,
+ "bad" : calc_hash1,
+ }
+
logger.warning(_("The checksum of the downloaded file did not match."))
+ logger.warning(_("Expected %(good)s but got %(bad)s.") % sums)
logger.warning(_("Trying an other mirror."))
+ # Remove the bad file.
+ self.cache.remove(cache_filename)
+
# Go to the next mirror.
- grabber.increment_mirror()
+ grabber.increment_mirror(grabber)
return os.path.join(self.cache.path, cache_filename)