From: "Matt Turner" <mattst88@gentoo.org> To: gentoo-commits@lists.gentoo.org Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/ Date: Sat, 20 Feb 2021 21:27:50 +0000 (UTC) [thread overview] Message-ID: <1613856449.caf55a942580e02e66ed846f5c3ab4ad5ab8846f.mattst88@gentoo> (raw) commit: caf55a942580e02e66ed846f5c3ab4ad5ab8846f Author: Felix Bier <Felix.Bier <AT> rohde-schwarz <DOT> com> AuthorDate: Thu Feb 4 00:37:06 2021 +0000 Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org> CommitDate: Sat Feb 20 21:27:29 2021 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=caf55a94 Extend get_repo_name to handle squashed repos This commit extends the method get_repo_name to also handle squashed repos. This is done by mounting the squash file to a temporary directory and then extracting the repository from that directory with the already existing code. This is motivated by wanting to mount each repo to e.g. /var/db/repos/<repo-name> in a later commit. For squashed repos, we don't know <repo-name> without mounting the repo first. For this reason, it is mounted to a temporary directory first to extract <repo-name>. Signed-off-by: Felix Bier <felix.bier <AT> rohde-schwarz.com> Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org> catalyst/support.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/catalyst/support.py b/catalyst/support.py index fc50fa34..37d53bc4 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -10,10 +10,12 @@ from subprocess import Popen import libmount from portage.repository.config import RepoConfig +from tempfile import TemporaryDirectory from snakeoil.bash import read_bash_dict from catalyst import log +from catalyst.context import namespace BASH_BINARY = "/bin/bash" @@ -148,7 +150,7 @@ def read_makeconf(mymakeconffile): return makeconf -def get_repo_name(repo_path): +def get_repo_name_from_dir(repo_path): """ Get the name of the repo at the given repo_path. References: @@ -164,6 +166,38 @@ def get_repo_name(repo_path): return repo_config.name +def get_repo_name_from_squash(repo_squash_path): + """ Get the name of the repo at the given repo_squash_path. + To obtain the name, the squash file is mounted to a temporary directory. + """ + + repo_name = None + + # Mount squash file to temp directory in separate mount namespace + with TemporaryDirectory() as temp, namespace(mount=True): + try: + source = str(repo_squash_path) + target = str(temp) + fstype = 'squashfs' + options = 'ro,loop' + cxt = libmount.Context(source=source, target=target, + fstype=fstype, options=options) + cxt.mount() + repo_name = get_repo_name_from_dir(target) + + except Exception as e: + raise CatalystError(f"Couldn't mount: {source}, {e}") from e + + return repo_name + + +def get_repo_name(repo_path): + if not Path(repo_path).is_dir(): + return get_repo_name_from_squash(repo_path) + + return get_repo_name_from_dir(repo_path) + + def ismount(path): """Like os.path.ismount, but also support bind mounts""" path = Path(path)
WARNING: multiple messages have this Message-ID (diff)
From: "Matt Turner" <mattst88@gentoo.org> To: gentoo-commits@lists.gentoo.org Subject: [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/ Date: Thu, 10 Jun 2021 00:48:42 +0000 (UTC) [thread overview] Message-ID: <1613856449.caf55a942580e02e66ed846f5c3ab4ad5ab8846f.mattst88@gentoo> (raw) Message-ID: <20210610004842.up5WGxk-sM_nQTfFCyqz1xHRZR2OLAhNOeyD0NUdxq4@z> (raw) commit: caf55a942580e02e66ed846f5c3ab4ad5ab8846f Author: Felix Bier <Felix.Bier <AT> rohde-schwarz <DOT> com> AuthorDate: Thu Feb 4 00:37:06 2021 +0000 Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org> CommitDate: Sat Feb 20 21:27:29 2021 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=caf55a94 Extend get_repo_name to handle squashed repos This commit extends the method get_repo_name to also handle squashed repos. This is done by mounting the squash file to a temporary directory and then extracting the repository from that directory with the already existing code. This is motivated by wanting to mount each repo to e.g. /var/db/repos/<repo-name> in a later commit. For squashed repos, we don't know <repo-name> without mounting the repo first. For this reason, it is mounted to a temporary directory first to extract <repo-name>. Signed-off-by: Felix Bier <felix.bier <AT> rohde-schwarz.com> Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org> catalyst/support.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/catalyst/support.py b/catalyst/support.py index fc50fa34..37d53bc4 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -10,10 +10,12 @@ from subprocess import Popen import libmount from portage.repository.config import RepoConfig +from tempfile import TemporaryDirectory from snakeoil.bash import read_bash_dict from catalyst import log +from catalyst.context import namespace BASH_BINARY = "/bin/bash" @@ -148,7 +150,7 @@ def read_makeconf(mymakeconffile): return makeconf -def get_repo_name(repo_path): +def get_repo_name_from_dir(repo_path): """ Get the name of the repo at the given repo_path. References: @@ -164,6 +166,38 @@ def get_repo_name(repo_path): return repo_config.name +def get_repo_name_from_squash(repo_squash_path): + """ Get the name of the repo at the given repo_squash_path. + To obtain the name, the squash file is mounted to a temporary directory. + """ + + repo_name = None + + # Mount squash file to temp directory in separate mount namespace + with TemporaryDirectory() as temp, namespace(mount=True): + try: + source = str(repo_squash_path) + target = str(temp) + fstype = 'squashfs' + options = 'ro,loop' + cxt = libmount.Context(source=source, target=target, + fstype=fstype, options=options) + cxt.mount() + repo_name = get_repo_name_from_dir(target) + + except Exception as e: + raise CatalystError(f"Couldn't mount: {source}, {e}") from e + + return repo_name + + +def get_repo_name(repo_path): + if not Path(repo_path).is_dir(): + return get_repo_name_from_squash(repo_path) + + return get_repo_name_from_dir(repo_path) + + def ismount(path): """Like os.path.ismount, but also support bind mounts""" path = Path(path)
next reply other threads:[~2021-02-20 21:27 UTC|newest] Thread overview: 116+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-20 21:27 Matt Turner [this message] 2021-06-10 0:48 ` [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/ Matt Turner -- strict thread matches above, loose matches on Subject: below -- 2024-10-12 12:44 [gentoo-commits] proj/catalyst:master " Andreas K. Hüttel 2024-07-30 11:08 Andreas K. Hüttel 2022-11-20 0:21 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner 2022-11-17 23:42 ` [gentoo-commits] proj/catalyst:master " Matt Turner 2022-02-16 22:34 Matt Turner 2021-06-11 3:30 Matt Turner 2021-06-10 0:48 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner 2021-02-20 21:27 ` [gentoo-commits] proj/catalyst:master " Matt Turner 2021-01-29 23:50 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner 2021-01-28 2:41 ` [gentoo-commits] proj/catalyst:master " Matt Turner 2020-11-14 16:37 Matt Turner 2020-10-30 22:41 Matt Turner 2020-10-30 22:41 Matt Turner 2020-10-08 21:17 Matt Turner 2020-06-05 21:13 Matt Turner 2020-05-21 20:26 Matt Turner 2020-05-21 20:25 Matt Turner 2020-05-21 20:25 Matt Turner 2020-05-21 20:25 Matt Turner 2020-05-20 3:39 [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner 2020-05-21 20:25 ` [gentoo-commits] proj/catalyst:master " Matt Turner 2020-05-20 1:52 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner 2020-05-21 20:25 ` [gentoo-commits] proj/catalyst:master " Matt Turner 2020-05-20 1:52 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner 2020-05-21 20:25 ` [gentoo-commits] proj/catalyst:master " Matt Turner 2020-05-20 1:52 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner 2020-05-21 20:25 ` [gentoo-commits] proj/catalyst:master " Matt Turner 2020-05-20 1:52 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner 2020-05-21 20:25 ` [gentoo-commits] proj/catalyst:master " Matt Turner 2020-04-30 22:56 Matt Turner 2020-04-30 22:56 Matt Turner 2020-04-30 22:56 Matt Turner 2020-04-22 5:52 Matt Turner 2020-04-22 5:52 Matt Turner 2020-04-22 5:52 Matt Turner 2020-04-17 19:52 Matt Turner 2020-04-17 19:52 Matt Turner 2020-04-10 21:04 Matt Turner 2019-10-20 0:00 Matt Turner 2019-08-26 16:52 Matt Turner 2019-06-16 18:35 Matt Turner 2019-02-05 3:02 Matt Turner 2018-10-02 15:57 Brian Dolbec 2018-10-01 16:30 Brian Dolbec 2018-09-12 6:43 Brian Dolbec 2018-07-21 18:54 Brian Dolbec 2017-12-30 18:25 Brian Dolbec 2017-12-29 2:27 Brian Dolbec 2017-12-29 0:35 Brian Dolbec 2017-12-07 7:24 Brian Dolbec 2017-12-07 7:21 Brian Dolbec 2017-12-06 18:51 Robin H. Johnson 2017-11-22 15:52 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2017-11-29 17:20 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2017-03-14 20:52 Mike Frysinger 2016-06-25 15:46 Brian Dolbec 2016-05-22 3:48 Mike Frysinger 2016-05-22 3:36 Mike Frysinger 2016-02-17 5:26 Brian Dolbec 2016-02-11 13:59 Mike Frysinger 2016-02-02 6:11 Brian Dolbec 2016-02-02 6:11 Brian Dolbec 2015-12-18 1:53 Mike Frysinger 2015-12-18 1:53 Mike Frysinger 2015-11-21 1:33 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-11-09 2:06 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-10-29 0:28 Mike Frysinger 2015-10-28 16:50 Mike Frysinger 2015-10-28 16:50 Mike Frysinger 2015-10-24 6:58 Mike Frysinger 2015-10-24 6:58 Mike Frysinger 2015-10-24 6:58 Mike Frysinger 2015-10-11 17:26 Mike Frysinger 2015-10-11 17:26 Mike Frysinger 2015-10-09 21:06 Mike Frysinger 2015-10-09 21:06 Mike Frysinger 2015-10-09 21:06 Mike Frysinger 2015-10-09 20:08 Mike Frysinger 2015-10-09 19:35 Mike Frysinger 2015-10-09 19:35 Mike Frysinger 2015-10-09 19:35 Mike Frysinger 2015-10-08 22:20 Mike Frysinger 2015-10-08 22:11 Mike Frysinger 2015-10-08 17:19 Mike Frysinger 2015-10-06 17:03 Mike Frysinger 2015-10-06 17:03 Mike Frysinger 2015-10-06 15:31 Mike Frysinger 2015-10-06 15:31 Mike Frysinger 2015-10-06 15:31 Mike Frysinger 2015-10-06 15:31 Mike Frysinger 2015-10-06 13:46 Mike Frysinger 2015-10-06 13:46 Mike Frysinger 2015-10-06 13:46 Mike Frysinger 2015-10-06 13:46 Mike Frysinger 2015-10-06 13:46 Mike Frysinger 2015-09-08 14:14 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-09-08 14:17 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-09-06 21:21 Brian Dolbec 2015-09-06 21:18 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-09-06 21:21 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-09-01 5:58 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-09-01 4:50 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-09-01 5:58 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-09-01 4:50 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-09-01 4:50 Brian Dolbec 2015-08-31 3:16 Richard Farina 2015-08-30 20:58 Brian Dolbec 2015-08-30 2:15 Brian Dolbec 2015-08-29 16:20 Brian Dolbec 2015-08-29 16:11 Brian Dolbec 2015-08-29 14:41 Brian Dolbec 2015-05-24 0:08 Brian Dolbec 2015-02-26 20:44 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-02-26 22:18 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-02-26 20:44 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-02-26 22:18 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-02-26 19:25 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-02-26 20:12 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-02-26 4:12 Brian Dolbec 2015-01-01 5:59 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-02-26 20:12 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-01-01 5:59 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-02-26 4:12 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-01-01 5:59 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-02-26 4:12 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-01-01 5:59 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-02-26 4:12 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2015-01-01 5:59 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2015-02-26 4:12 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2014-09-11 3:26 Brian Dolbec 2014-09-11 3:26 Brian Dolbec 2014-05-05 19:17 Brian Dolbec 2014-04-02 20:09 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2014-05-05 19:17 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2014-04-02 20:09 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2014-05-05 19:17 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2014-04-02 20:09 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2014-05-05 19:17 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec 2014-03-22 22:25 [gentoo-commits] proj/catalyst:pending " Brian Dolbec 2014-03-02 22:55 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1613856449.caf55a942580e02e66ed846f5c3ab4ad5ab8846f.mattst88@gentoo \ --to=mattst88@gentoo.org \ --cc=gentoo-commits@lists.gentoo.org \ --cc=gentoo-dev@lists.gentoo.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox