1 |
commit: caf55a942580e02e66ed846f5c3ab4ad5ab8846f |
2 |
Author: Felix Bier <Felix.Bier <AT> rohde-schwarz <DOT> com> |
3 |
AuthorDate: Thu Feb 4 00:37:06 2021 +0000 |
4 |
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Feb 20 21:27:29 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=caf55a94 |
7 |
|
8 |
Extend get_repo_name to handle squashed repos |
9 |
|
10 |
This commit extends the method get_repo_name to also handle |
11 |
squashed repos. This is done by mounting the squash file to |
12 |
a temporary directory and then extracting the repository from |
13 |
that directory with the already existing code. |
14 |
|
15 |
This is motivated by wanting to mount each repo |
16 |
to e.g. /var/db/repos/<repo-name> in a later commit. |
17 |
For squashed repos, we don't know <repo-name> without |
18 |
mounting the repo first. For this reason, it is mounted to |
19 |
a temporary directory first to extract <repo-name>. |
20 |
|
21 |
Signed-off-by: Felix Bier <felix.bier <AT> rohde-schwarz.com> |
22 |
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org> |
23 |
|
24 |
catalyst/support.py | 36 +++++++++++++++++++++++++++++++++++- |
25 |
1 file changed, 35 insertions(+), 1 deletion(-) |
26 |
|
27 |
diff --git a/catalyst/support.py b/catalyst/support.py |
28 |
index fc50fa34..37d53bc4 100644 |
29 |
--- a/catalyst/support.py |
30 |
+++ b/catalyst/support.py |
31 |
@@ -10,10 +10,12 @@ from subprocess import Popen |
32 |
import libmount |
33 |
|
34 |
from portage.repository.config import RepoConfig |
35 |
+from tempfile import TemporaryDirectory |
36 |
|
37 |
from snakeoil.bash import read_bash_dict |
38 |
|
39 |
from catalyst import log |
40 |
+from catalyst.context import namespace |
41 |
|
42 |
BASH_BINARY = "/bin/bash" |
43 |
|
44 |
@@ -148,7 +150,7 @@ def read_makeconf(mymakeconffile): |
45 |
return makeconf |
46 |
|
47 |
|
48 |
-def get_repo_name(repo_path): |
49 |
+def get_repo_name_from_dir(repo_path): |
50 |
""" Get the name of the repo at the given repo_path. |
51 |
|
52 |
References: |
53 |
@@ -164,6 +166,38 @@ def get_repo_name(repo_path): |
54 |
return repo_config.name |
55 |
|
56 |
|
57 |
+def get_repo_name_from_squash(repo_squash_path): |
58 |
+ """ Get the name of the repo at the given repo_squash_path. |
59 |
+ To obtain the name, the squash file is mounted to a temporary directory. |
60 |
+ """ |
61 |
+ |
62 |
+ repo_name = None |
63 |
+ |
64 |
+ # Mount squash file to temp directory in separate mount namespace |
65 |
+ with TemporaryDirectory() as temp, namespace(mount=True): |
66 |
+ try: |
67 |
+ source = str(repo_squash_path) |
68 |
+ target = str(temp) |
69 |
+ fstype = 'squashfs' |
70 |
+ options = 'ro,loop' |
71 |
+ cxt = libmount.Context(source=source, target=target, |
72 |
+ fstype=fstype, options=options) |
73 |
+ cxt.mount() |
74 |
+ repo_name = get_repo_name_from_dir(target) |
75 |
+ |
76 |
+ except Exception as e: |
77 |
+ raise CatalystError(f"Couldn't mount: {source}, {e}") from e |
78 |
+ |
79 |
+ return repo_name |
80 |
+ |
81 |
+ |
82 |
+def get_repo_name(repo_path): |
83 |
+ if not Path(repo_path).is_dir(): |
84 |
+ return get_repo_name_from_squash(repo_path) |
85 |
+ |
86 |
+ return get_repo_name_from_dir(repo_path) |
87 |
+ |
88 |
+ |
89 |
def ismount(path): |
90 |
"""Like os.path.ismount, but also support bind mounts""" |
91 |
path = Path(path) |