From: Andrew Gaffney Date: Mon, 14 Sep 2009 01:19:08 +0000 (-0500) Subject: Rewrite unpack() so it doesn't suck X-Git-Tag: CATALYST-2.0.10~3^2~97 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2f33dfc5335f113472a51d55ce8f9975699d5dfa;p=catalyst.git Rewrite unpack() so it doesn't suck --- diff --git a/ChangeLog b/ChangeLog index b3fcdb2e..6f7b917c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ # Distributed under the GPL v2 # $Id$ + 14 Sep 2009; Andrew Gaffney + modules/catalyst/target/generic_stage.py: + Rewrite unpack() so it doesn't suck + 14 Sep 2009; Andrew Gaffney modules/catalyst/target/generic.py: Beef up autoresume to record path metadata and check it later diff --git a/modules/catalyst/target/generic_stage.py b/modules/catalyst/target/generic_stage.py index d9f6cd34..a871535c 100644 --- a/modules/catalyst/target/generic_stage.py +++ b/modules/catalyst/target/generic_stage.py @@ -501,124 +501,34 @@ class generic_stage_target(generic_target): raise CatalystError, "Unable to auto-unbind "+x def unpack(self): - unpack=True - - clst_unpack_hash = catalyst.util.readfile(self.settings["autoresume_path"]+\ - "unpack") - - if "SEEDCACHE" in self.settings: - if os.path.isdir(self.settings["source_path"]): - """ SEEDCACHE Is a directory, use rsync """ - unpack_cmd="rsync -a --delete "+self.settings["source_path"]+\ - " "+self.settings["chroot_path"] - display_msg="\nStarting rsync from "+\ - self.settings["source_path"]+"\nto "+\ - self.settings["chroot_path"]+\ - " (This may take some time) ...\n" - error_msg="Rsync of "+self.settings["source_path"]+" to "+\ - self.settings["chroot_path"]+" failed." - else: - """ SEEDCACHE is a not a directory, try untar'ing """ - msg("Referenced SEEDCACHE does not appear to be a directory, trying to untar...") - display_msg="\nStarting tar extract from "+\ - self.settings["source_path"]+"\nto "+\ - self.settings["chroot_path"]+\ - " (This may take some time) ...\n" - unpack_cmd="tar xjpf "+self.settings["source_path"]+" -C "+\ - self.settings["chroot_path"] - error_msg="Tarball extraction of "+\ - self.settings["source_path"]+" to "+\ - self.settings["chroot_path"]+" failed." - else: - """ No SEEDCACHE, use tar """ - display_msg="\nStarting tar extract from "+\ - self.settings["source_path"]+"\nto "+\ - self.settings["chroot_path"]+\ - " (This may take some time) ...\n" - unpack_cmd="tar xjpf "+self.settings["source_path"]+" -C "+\ - self.settings["chroot_path"] - error_msg="Tarball extraction of "+self.settings["source_path"]+\ - " to "+self.settings["chroot_path"]+" failed." - - if self.check_autoresume(): - if os.path.isdir(self.settings["source_path"]) \ - and self.check_autoresume("unpack"): - """ Autoresume is valid, SEEDCACHE is valid """ - unpack=False - invalid_snapshot=False - - elif os.path.isfile(self.settings["source_path"]) \ - and self.settings["source_path_hash"]==clst_unpack_hash: - """ Autoresume is valid, tarball is valid """ - unpack=False - invalid_snapshot=True - - elif os.path.isdir(self.settings["source_path"]) \ - and not self.check_autoresume("unpack"): - """ Autoresume is invalid, SEEDCACHE """ - unpack=True - invalid_snapshot=False - - elif os.path.isfile(self.settings["source_path"]) \ - and self.settings["source_path_hash"]!=clst_unpack_hash: - """ Autoresume is invalid, tarball """ - unpack=True - invalid_snapshot=True - else: - """ No autoresume, SEEDCACHE """ - if "SEEDCACHE" in self.settings: - """ SEEDCACHE so let's run rsync and let it clean up """ - if os.path.isdir(self.settings["source_path"]): - unpack=True - invalid_snapshot=False - elif os.path.isfile(self.settings["source_path"]): - """ Tarball so unpack and remove anything already there """ - unpack=True - invalid_snapshot=True - """ No autoresume, no SEEDCACHE """ - else: - """ Tarball so unpack and remove anything already there """ - if os.path.isfile(self.settings["source_path"]): - unpack=True - invalid_snapshot=True - elif os.path.isdir(self.settings["source_path"]): - """ We should never reach this, so something is very wrong """ - raise CatalystError,\ - "source path is a dir but seedcache is not enabled" - - if unpack: - self.mount_safety_check() - - if invalid_snapshot: - if self.check_autoresume(): - msg("No Valid Resume point detected, cleaning up...") + if self.check_autoresume("unpack"): + msg("Resume point detected, skipping unpack operation...") + return - self.clear_autoresume() - self.clear_chroot() + self.mount_safety_check() - if not os.path.exists(self.settings["chroot_path"]): - os.makedirs(self.settings["chroot_path"]) + self.clear_chroot() - if not os.path.exists(self.settings["chroot_path"]+"/tmp"): - os.makedirs(self.settings["chroot_path"]+"/tmp",1777) + if not os.path.exists(self.settings["chroot_path"]): + catalyst.util.mkdir(self.settings["chroot_path"]) - if "PKGCACHE" in self.settings: - if not os.path.exists(self.settings["pkgcache_path"]): - os.makedirs(self.settings["pkgcache_path"],0755) + if not os.path.exists(self.settings["chroot_path"]+"/tmp"): + catalyst.util.mkdir(self.settings["chroot_path"]+"/tmp", 1777) - if "KERNCACHE" in self.settings: - if not os.path.exists(self.settings["kerncache_path"]): - os.makedirs(self.settings["kerncache_path"],0755) + if "PKGCACHE" in self.settings: + if not os.path.exists(self.settings["pkgcache_path"]): + catalyst.util.mkdir(self.settings["pkgcache_path"]) - msg(display_msg) - cmd(unpack_cmd,error_msg,env=self.env) + if "KERNCACHE" in self.settings: + if not os.path.exists(self.settings["kerncache_path"]): + catalyst.util.mkdir(self.settings["kerncache_path"]) - if "source_path_hash" in self.settings: - self.set_autoresume("unpack", self.settings["source_path_hash"]) - else: - self.set_autoresume("unpack") + if "SEEDCACHE" in self.settings and os.path.isdir(self.settings["source_path"]): + catalyst.util.rsync(self.settings["source_path"], self.settings["chroot_path"], delete=True) else: - msg("Resume point detected, skipping unpack operation...") + catalyst.util.unpack_tarball(self.settings["source_path"], self.settings["chroot_path"]) + + self.set_autoresume("unpack", self.settings["source_path"]) def unpack_snapshot(self): unpack=True