=== modified file 'preupgrade/__init__.py' --- preupgrade/__init__.py 2008-11-14 17:03:17 +0000 +++ preupgrade/__init__.py 2008-11-17 16:44:44 +0000 @@ -31,6 +31,7 @@ import yum, rpm import yum.Errors import rpmUtils.arch +from yum.misc import checksum from yum.parser import varReplace from yum.constants import * @@ -265,6 +266,7 @@ # FIXME what happens if the network isn't up yet? self.release_map = self.retrieve_release_info(configfile) self.bootpath='/boot/upgrade' + self.image_csums = {} # filename = (csumtype, csum) # Noisy if these plugins don't exist, but doesn't raise an exception self._getConfig(enabled_plugins=['blacklist','whiteout']) if release: @@ -461,7 +463,12 @@ self.mainimage = 'images/stage2.img' except ConfigParser.NoOptionError, e: raise PUError, "Invalid treeinfo: %s" % str(e) - + + if cp.has_section('checksums'): + for opt_fn in cp.options('checksums'): + (csum_type, csum) = cp.get('checksums', opt_fn).split(':') + self.image_csums[opt_fn] = (csum_type, csum) + tif.close() @@ -489,13 +496,19 @@ # see if we have it and if it is the right size if os.path.exists(local): - local_stat = os.stat(local) - if int(local_stat.st_size) == int(mysize): - # File exists and it's the right size.. guess it's probably OK - # TODO: we have sha1sums in .treeinfo now - check 'em! - return True + if self.image_csums.has_key(fileinfo): + csumtype, csum = self.image_csums[fileinfo]: + if csum == checksum(csumtype, local): + return True + else: + os.unlink(local) else: - os.unlink(local) + local_stat = os.stat(local) + if int(local_stat.st_size) == int(mysize): + # File exists and it's the right size.. guess it's probably OK + return True + else: + os.unlink(local) # if we are this far we're going to try to download it # check for available disk space @@ -509,7 +522,13 @@ except URLGrabError, e: os.unlink(local) raise PUError, "failure downloading %s: %s" % (item_fname, e) - + + if self.image_csums.has_key(fileinfo): + csumtype, csum = self.image_csums[fileinfo]: + if csum != checksum(csumtype, local): + os.unlink(local) + raise PUError, "failure downloading %s: %s" % (item_fname, e) + return True def remove_boot_files(self):