From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B9D2513835A for ; Sat, 20 Feb 2021 21:27:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DBA95E0880; Sat, 20 Feb 2021 21:27:52 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C70E1E0880 for ; Sat, 20 Feb 2021 21:27:52 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DD59833BEA6 for ; Sat, 20 Feb 2021 21:27:51 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3F8AA4E1 for ; Sat, 20 Feb 2021 21:27:50 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1613856449.caf55a942580e02e66ed846f5c3ab4ad5ab8846f.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/support.py X-VCS-Directories: catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: caf55a942580e02e66ed846f5c3ab4ad5ab8846f X-VCS-Branch: master Date: Sat, 20 Feb 2021 21:27:50 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: c8fdd342-64dc-4d1a-a3f5-56018f4e12cf X-Archives-Hash: 4b77eda40a3874216d90d2374018132f commit: caf55a942580e02e66ed846f5c3ab4ad5ab8846f Author: Felix Bier rohde-schwarz com> AuthorDate: Thu Feb 4 00:37:06 2021 +0000 Commit: Matt Turner gentoo 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/ in a later commit. For squashed repos, we don't know without mounting the repo first. For this reason, it is mounted to a temporary directory first to extract . Signed-off-by: Felix Bier rohde-schwarz.com> Signed-off-by: Matt Turner 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) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 638FB1382C5 for ; Thu, 10 Jun 2021 00:48:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9953DE08DD; Thu, 10 Jun 2021 00:48:45 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7CF12E08DD for ; Thu, 10 Jun 2021 00:48:45 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4AA2733BEAE for ; Thu, 10 Jun 2021 00:48:44 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C114A7A6 for ; Thu, 10 Jun 2021 00:48:42 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1613856449.caf55a942580e02e66ed846f5c3ab4ad5ab8846f.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/support.py X-VCS-Directories: catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: caf55a942580e02e66ed846f5c3ab4ad5ab8846f X-VCS-Branch: wip/mattst88 Date: Thu, 10 Jun 2021 00:48:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 852f149f-0247-4ba4-8921-40135fba3eff X-Archives-Hash: a25aac3f8df985dbe6890c7dd51d59d8 Message-ID: <20210610004842.up5WGxk-sM_nQTfFCyqz1xHRZR2OLAhNOeyD0NUdxq4@z> commit: caf55a942580e02e66ed846f5c3ab4ad5ab8846f Author: Felix Bier rohde-schwarz com> AuthorDate: Thu Feb 4 00:37:06 2021 +0000 Commit: Matt Turner gentoo 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/ in a later commit. For squashed repos, we don't know without mounting the repo first. For this reason, it is mounted to a temporary directory first to extract . Signed-off-by: Felix Bier rohde-schwarz.com> Signed-off-by: Matt Turner 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)