1 |
commit: 4c4a82badb5ef8bd472dae7b530ef87a4c1f9127 |
2 |
Author: Matt Turner <mattst88 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Apr 19 01:10:51 2020 +0000 |
4 |
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Apr 23 18:20:35 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=4c4a82ba |
7 |
|
8 |
catalyst: Clean up bind() |
9 |
|
10 |
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org> |
11 |
|
12 |
catalyst/base/stagebase.py | 62 +++++++++++++++++++++++++--------------------- |
13 |
1 file changed, 34 insertions(+), 28 deletions(-) |
14 |
|
15 |
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py |
16 |
index 275c07eb..9aecf013 100644 |
17 |
--- a/catalyst/base/stagebase.py |
18 |
+++ b/catalyst/base/stagebase.py |
19 |
@@ -906,35 +906,41 @@ class StageBase(TargetBase, ClearBase, GenBase): |
20 |
|
21 |
def bind(self): |
22 |
for x in [x for x in self.mount if self.mount[x]['enable']]: |
23 |
- log.debug('bind(); x = %s', x) |
24 |
- target = normpath(self.settings['chroot_path'] + |
25 |
- self.mount[x]['target']) |
26 |
- ensure_dirs(target, mode=0o755) |
27 |
- |
28 |
- if not os.path.exists(self.mount[x]['source']): |
29 |
- if self.mount[x]['source'] not in ("maybe_tmpfs", "tmpfs", "shmfs"): |
30 |
- ensure_dirs(self.mount[x]['source'], mode=0o755) |
31 |
- |
32 |
- src = self.mount[x]['source'] |
33 |
- log.debug('bind(); src = %s', src) |
34 |
- if src == "maybe_tmpfs": |
35 |
- if "var_tmpfs_portage" in self.settings: |
36 |
- _cmd = ['mount', '-t', 'tmpfs', |
37 |
- '-o', 'size=' + |
38 |
- self.settings['var_tmpfs_portage'] + 'G', |
39 |
- src, target] |
40 |
- elif src == "tmpfs": |
41 |
- _cmd = ['mount', '-t', 'tmpfs', src, target] |
42 |
+ if str(self.mount[x]['source']) == 'config': |
43 |
+ raise CatalystError(f'"{x}" bind mount source is not configured') |
44 |
+ if str(self.mount[x]['target']) == 'config': |
45 |
+ raise CatalystError(f'"{x}" bind mount target is not configured') |
46 |
+ |
47 |
+ source = str(self.mount[x]['source']) |
48 |
+ target = self.settings['chroot_path'] + str(self.mount[x]['target']) |
49 |
+ |
50 |
+ log.debug('bind %s: "%s" -> "%s"', x, source, target) |
51 |
+ |
52 |
+ if source == 'maybe_tmpfs': |
53 |
+ if 'var_tmpfs_portage' not in self.settings: |
54 |
+ return |
55 |
+ |
56 |
+ _cmd = ['mount', '-t', 'tmpfs', '-o', 'size=' + |
57 |
+ self.settings['var_tmpfs_portage'] + 'G', source, |
58 |
+ target] |
59 |
+ elif source == 'tmpfs': |
60 |
+ _cmd = ['mount', '-t', 'tmpfs', source, target] |
61 |
+ elif source == 'shmfs': |
62 |
+ _cmd = ['mount', '-t', 'tmpfs', '-o', 'noexec,nosuid,nodev', |
63 |
+ 'shm', target] |
64 |
else: |
65 |
- if src == "shmfs": |
66 |
- _cmd = ['mount', '-t', 'tmpfs', '-o', |
67 |
- 'noexec,nosuid,nodev', 'shm', target] |
68 |
- else: |
69 |
- _cmd = ['mount', '--bind', src, target] |
70 |
- if _cmd: |
71 |
- log.debug('bind(); _cmd = %s', _cmd) |
72 |
- cmd(_cmd, env=self.env, fail_func=self.unbind) |
73 |
- log.debug('bind(); finished :D') |
74 |
+ _cmd = ['mount', '--bind', source, target] |
75 |
+ |
76 |
+ source = Path(self.mount[x]['source']) |
77 |
+ |
78 |
+ # We may need to create the source of the bind mount. E.g., in the |
79 |
+ # case of an empty package cache we must create the directory that |
80 |
+ # the binary packages will be stored into. |
81 |
+ source.mkdir(mode=0o755, exist_ok=True) |
82 |
+ |
83 |
+ Path(target).mkdir(mode=0o755, parents=True, exist_ok=True) |
84 |
+ |
85 |
+ cmd(_cmd, env=self.env, fail_func=self.unbind) |
86 |
|
87 |
def unbind(self): |
88 |
ouch = 0 |