From d2f2ea74bc7755cd0d2d975566d781c3630f406f Mon Sep 17 00:00:00 2001 From: Devan Franchini Date: Wed, 22 May 2013 19:54:59 -0400 Subject: [PATCH] Clears autoresume if spec has been changed --- catalyst/hash_utils.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- catalyst/main.py | 9 +++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/catalyst/hash_utils.py b/catalyst/hash_utils.py index cd31ad3..5ad93c3 100644 --- a/catalyst/hash_utils.py +++ b/catalyst/hash_utils.py @@ -102,5 +102,54 @@ class HashMap(object): print header+" (%s) = %s" % (short_file, result) return result - + def gen_chksumfile(self, file_, filename, storedir, hash_type, exit_on_error=True): + filename = filename + modtime = os.path.getmtime(file_) + chksum = self.calc_hash2(file_, hash_type) + chksum = chksum[:-1] + " " +str(modtime) + try: + with open(os.path.join(storedir,filename), 'w') as chksumfile: + chksumfile.write(chksum) + except IOError: + if exit_on_error: + raise CatalystError("Could not generate checksum for " + file_, print_traceback=True) + return False + return True + + def evaluate_spec(self, spec, filename, storedir, hash_type): + chksumfile = os.path.join(storedir,filename) + with open(chksumfile, 'r') as specfile: + lines = specfile.readlines() + hash_value = lines[0].split() + hash_value = hash_value[1] + chksum, filename, modtime = lines[1].split() + modtime_n = os.path.getmtime(spec) + # First check the modification time to save + # resources, if it hasn't been modified, + # don't bother generating a second checksum. + if not modtime == modtime_n: + hash_value_n = self.calc_hash2(spec, hash_type.lower()).split() + hash_value_n = hash_value_n[1] + chksum_n = self.calc_hash2(spec, hash_type).split() + chksum_n = chksum_n[3] + # Check the hash value in the file against + # the current hash value from the config. + if not hash_value == hash_value_n: + chksum_n = self.calc_hash2(spec, hash_value.lower()).split() + chksum_n = chksum_n[3] + + if not chksum == chksum_n: + return False + + self.gen_chksumfile(spec, filename, storedir, hash_value_n.lower()) + return True + + def check_chksum(self, spec, filename, storedir, hash_type): + file_location=os.path.join(storedir,filename) + if os.path.exists(file_location): + return self.evaluate_spec(spec, filename, storedir, hash_type) + else: + # If the checksum doesn't exist, this is the first time + # using this spec file, so no need to check against it. + return self.gen_chksumfile(spec, filename, storedir, hash_type) diff --git a/catalyst/main.py b/catalyst/main.py index 05904ec..4054429 100644 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -330,6 +330,15 @@ def main(): if myspecfile: spec = catalyst.config.SpecParser(myspecfile) addlargs.update(spec.get_values()) + + name_components = [] + for key in ["target", "subarch", "version_stamp"]: + if key in addlargs: + name_components.append(addlargs[key]) + + filename = "-".join(name_components) + ".DIGESTS" + if not hash_map.check_chksum(myspecfile, filename, conf_values["storedir"], conf_values["hash_function"]): + conf_values["options"].add("clear-autoresume") if mycmdline: try: -- 1.8.1.5