From: Andrew Gaffney Date: Mon, 14 Sep 2009 01:18:35 +0000 (-0500) Subject: Beef up autoresume to record path metadata and check it later X-Git-Tag: CATALYST-2.0.10~3^2~98 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d6fcc1ff4bc814e0ef5c231f08889b7ea315e997;p=catalyst.git Beef up autoresume to record path metadata and check it later --- diff --git a/ChangeLog b/ChangeLog index 20712efd..b3fcdb2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ # Distributed under the GPL v2 # $Id$ + 14 Sep 2009; Andrew Gaffney + modules/catalyst/target/generic.py: + Beef up autoresume to record path metadata and check it later + 13 Sep 2009; Andrew Gaffney modules/catalyst/target/snapshot.py: Add --exclude /packages/ to the rsync line for the snapshot diff --git a/modules/catalyst/target/generic.py b/modules/catalyst/target/generic.py index fdf2dc7c..ce9e0985 100644 --- a/modules/catalyst/target/generic.py +++ b/modules/catalyst/target/generic.py @@ -9,8 +9,6 @@ from catalyst.spawn import cmd class generic_target: - _autoresume_invalid = False - def __init__(self): # if myspec and addlargs: # catalyst.util.addl_arg_parse(myspec,addlargs,self.required_values,self.valid_values) @@ -39,21 +37,40 @@ class generic_target: def check_autoresume(self, step=None): if "AUTORESUME" in self.settings: if step: - if self._autoresume_invalid: - return False - elif os.path.exists(self.settings["autoresume_path"] + step): - return True + if os.path.exists(self.settings["autoresume_path"] + step): + autoresume_size = os.path.getsize(self.settings["autoresume_path"] + step) + if autoresume_size == 0: + return True + else: + metadata = catalyst.util.readfile(self.settings["autoresume_path"] + step) + metadata = metadata.split() + if os.path.exists(metadata[0]): + if os.path.isfile(metadata[0]): + path_hash = catalyst.hash.generate_hash(metadata[0], hash_function=self.settings["hash_function"], verbose=False) + if path_hash != metadata[1]: + self.clear_autoresume() + return False + else: + self.clear_autoresume() + return False + return True else: - self._autoresume_invalid = True + self.clear_autoresume() return False else: return True return False - def set_autoresume(self, step, value=""): - if value: + def set_autoresume(self, step, path=None): + if path: + metadata = "" + if os.path.isfile(path): + path_hash = catalyst.hash.generate_hash(path, hash_function=self.settings["hash_function"], verbose=False) + metadata = path + " " + path_hash + else: + metadata = path myf=open(self.settings["autoresume_path"] + step, "w") - myf.write(value) + myf.write(metadata) myf.close() else: catalyst.util.touch(self.settings["autoresume_path"] + step)