diff options
author | Brian Dolbec <dolsen@gentoo.org> | 2017-04-06 13:51:23 -0700 |
---|---|---|
committer | Brian Dolbec <dolsen@gentoo.org> | 2017-11-21 17:16:22 -0800 |
commit | 57055cb085a23358febf61b2c7d36627fc2815dd (patch) | |
tree | 8e74c6c67bc0d43aa662eace2648024f0a036d2e | |
parent | Unify stage cleaning (diff) | |
download | catalyst-57055cb085a23358febf61b2c7d36627fc2815dd.tar.gz catalyst-57055cb085a23358febf61b2c7d36627fc2815dd.tar.bz2 catalyst-57055cb085a23358febf61b2c7d36627fc2815dd.zip |
stage1: Fix seedcache to clean out the original seed root, keep only the stage1root
Signed-off-by: Brian Dolbec <dolsen@gentoo.org>
-rw-r--r-- | catalyst/fileops.py | 23 | ||||
-rw-r--r-- | catalyst/targets/stage1.py | 39 |
2 files changed, 61 insertions, 1 deletions
diff --git a/catalyst/fileops.py b/catalyst/fileops.py index ef4ee8d1..5e51f1fc 100644 --- a/catalyst/fileops.py +++ b/catalyst/fileops.py @@ -107,3 +107,26 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False, def clear_path(target): """Nuke |target| regardless of it being a dir or file.""" clear_dir(target, remove=True) + + +def move_path(src, dest): + '''Move a source target to a new destination + + :param src: source path to move + :param dest: destination path to move it to + :returns: boolean + ''' + log.debug('Start move_path(%s, %s)', src, dest) + if os.path.isdir(src) and not os.path.islink(src): + if os.path.exists(dest): + log.warning('Removing existing target destination: %s', dest) + if not clear_dir(dest, remove=True): + return False + log.debug('Moving source...') + try: + shutil.move(src, dest) + except Exception: + log.error('move_path failed', exc_info=True) + return False + return True + return False diff --git a/catalyst/targets/stage1.py b/catalyst/targets/stage1.py index 18ef520d..cc4366b6 100644 --- a/catalyst/targets/stage1.py +++ b/catalyst/targets/stage1.py @@ -9,7 +9,7 @@ from snakeoil import fileutils from catalyst import log from catalyst.support import normpath -from catalyst.fileops import ensure_dirs +from catalyst.fileops import ensure_dirs, move_path from catalyst.base.stagebase import StageBase @@ -86,3 +86,40 @@ class stage1(StageBase): self.mounts.append("stage1root/proc") self.target_mounts["stage1root/proc"] = "/tmp/stage1root/proc" self.mountmap["stage1root/proc"] = "/proc" + + def set_completion_action_sequences(self): + '''Override function for stage1 + + Its purpose is to move the new stage1root out of the seed stage + and rename it to the stage1 chroot_path after cleaning the seed stage + chroot for re-use in stage2 without the need to unpack it. + ''' + if "fetch" not in self.settings["options"]: + self.settings["action_sequence"].append("capture") + if "keepwork" in self.settings["options"]: + self.settings["action_sequence"].append("clear_autoresume") + elif "seedcache" in self.settings["options"]: + self.settings["action_sequence"].append("remove_autoresume") + self.settings["action_sequence"].append("clean_stage1") + else: + self.settings["action_sequence"].append("remove_autoresume") + self.settings["action_sequence"].append("remove_chroot") + return + + + def clean_stage1(self): + '''seedcache is enabled, so salvage the /tmp/stage1root, + remove the seed chroot''' + log.notice('Salvaging the stage1root from the chroot path ...') + # move the self.settings["stage_path"] outside of the self.settings["chroot_path"] + tmp_path = normpath(self.settings["storedir"] + "/tmp/" + "stage1root") + if move_path(self.settings["stage_path"], tmp_path): + self.remove_chroot() + # move it to self.settings["chroot_path"] + if not move_path(tmp_path, self.settings["chroot_path"]): + log.error('clean_stage1 failed, see previous log messages for details') + return False + log.notice('Successfully moved and cleaned the stage1root for the seedcache') + return True + log.error('clean_stage1 failed to move the stage1root to a temporary loation') + return False |