1 |
commit: 57055cb085a23358febf61b2c7d36627fc2815dd |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Apr 6 20:51:23 2017 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Nov 22 01:16:22 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=57055cb0 |
7 |
|
8 |
stage1: Fix seedcache to clean out the original seed root, keep only the stage1root |
9 |
|
10 |
Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org> |
11 |
|
12 |
catalyst/fileops.py | 23 +++++++++++++++++++++++ |
13 |
catalyst/targets/stage1.py | 39 ++++++++++++++++++++++++++++++++++++++- |
14 |
2 files changed, 61 insertions(+), 1 deletion(-) |
15 |
|
16 |
diff --git a/catalyst/fileops.py b/catalyst/fileops.py |
17 |
index ef4ee8d1..5e51f1fc 100644 |
18 |
--- a/catalyst/fileops.py |
19 |
+++ b/catalyst/fileops.py |
20 |
@@ -107,3 +107,26 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False, |
21 |
def clear_path(target): |
22 |
"""Nuke |target| regardless of it being a dir or file.""" |
23 |
clear_dir(target, remove=True) |
24 |
+ |
25 |
+ |
26 |
+def move_path(src, dest): |
27 |
+ '''Move a source target to a new destination |
28 |
+ |
29 |
+ :param src: source path to move |
30 |
+ :param dest: destination path to move it to |
31 |
+ :returns: boolean |
32 |
+ ''' |
33 |
+ log.debug('Start move_path(%s, %s)', src, dest) |
34 |
+ if os.path.isdir(src) and not os.path.islink(src): |
35 |
+ if os.path.exists(dest): |
36 |
+ log.warning('Removing existing target destination: %s', dest) |
37 |
+ if not clear_dir(dest, remove=True): |
38 |
+ return False |
39 |
+ log.debug('Moving source...') |
40 |
+ try: |
41 |
+ shutil.move(src, dest) |
42 |
+ except Exception: |
43 |
+ log.error('move_path failed', exc_info=True) |
44 |
+ return False |
45 |
+ return True |
46 |
+ return False |
47 |
|
48 |
diff --git a/catalyst/targets/stage1.py b/catalyst/targets/stage1.py |
49 |
index 18ef520d..cc4366b6 100644 |
50 |
--- a/catalyst/targets/stage1.py |
51 |
+++ b/catalyst/targets/stage1.py |
52 |
@@ -9,7 +9,7 @@ from snakeoil import fileutils |
53 |
|
54 |
from catalyst import log |
55 |
from catalyst.support import normpath |
56 |
-from catalyst.fileops import ensure_dirs |
57 |
+from catalyst.fileops import ensure_dirs, move_path |
58 |
from catalyst.base.stagebase import StageBase |
59 |
|
60 |
|
61 |
@@ -86,3 +86,40 @@ class stage1(StageBase): |
62 |
self.mounts.append("stage1root/proc") |
63 |
self.target_mounts["stage1root/proc"] = "/tmp/stage1root/proc" |
64 |
self.mountmap["stage1root/proc"] = "/proc" |
65 |
+ |
66 |
+ def set_completion_action_sequences(self): |
67 |
+ '''Override function for stage1 |
68 |
+ |
69 |
+ Its purpose is to move the new stage1root out of the seed stage |
70 |
+ and rename it to the stage1 chroot_path after cleaning the seed stage |
71 |
+ chroot for re-use in stage2 without the need to unpack it. |
72 |
+ ''' |
73 |
+ if "fetch" not in self.settings["options"]: |
74 |
+ self.settings["action_sequence"].append("capture") |
75 |
+ if "keepwork" in self.settings["options"]: |
76 |
+ self.settings["action_sequence"].append("clear_autoresume") |
77 |
+ elif "seedcache" in self.settings["options"]: |
78 |
+ self.settings["action_sequence"].append("remove_autoresume") |
79 |
+ self.settings["action_sequence"].append("clean_stage1") |
80 |
+ else: |
81 |
+ self.settings["action_sequence"].append("remove_autoresume") |
82 |
+ self.settings["action_sequence"].append("remove_chroot") |
83 |
+ return |
84 |
+ |
85 |
+ |
86 |
+ def clean_stage1(self): |
87 |
+ '''seedcache is enabled, so salvage the /tmp/stage1root, |
88 |
+ remove the seed chroot''' |
89 |
+ log.notice('Salvaging the stage1root from the chroot path ...') |
90 |
+ # move the self.settings["stage_path"] outside of the self.settings["chroot_path"] |
91 |
+ tmp_path = normpath(self.settings["storedir"] + "/tmp/" + "stage1root") |
92 |
+ if move_path(self.settings["stage_path"], tmp_path): |
93 |
+ self.remove_chroot() |
94 |
+ # move it to self.settings["chroot_path"] |
95 |
+ if not move_path(tmp_path, self.settings["chroot_path"]): |
96 |
+ log.error('clean_stage1 failed, see previous log messages for details') |
97 |
+ return False |
98 |
+ log.notice('Successfully moved and cleaned the stage1root for the seedcache') |
99 |
+ return True |
100 |
+ log.error('clean_stage1 failed to move the stage1root to a temporary loation') |
101 |
+ return False |