From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 234DC1389F5 for ; Mon, 17 Nov 2014 17:43:59 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 12BA1E086C; Mon, 17 Nov 2014 17:43:58 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A586DE086C for ; Mon, 17 Nov 2014 17:43:57 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 9CC083404F5 for ; Mon, 17 Nov 2014 17:43:56 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CF206A533 for ; Mon, 17 Nov 2014 17:43:54 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1416246075.77c4a4d2cb63d8e7c95840c44f5bf9b597316120.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: bin/portageq pym/portage/data.py X-VCS-Directories: bin/ pym/portage/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 77c4a4d2cb63d8e7c95840c44f5bf9b597316120 X-VCS-Branch: master Date: Mon, 17 Nov 2014 17:43:54 +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-Archives-Salt: c2668580-c81b-4ce4-bf76-9caab6e8ede3 X-Archives-Hash: 24b7af3ec9d237d160cf7290eca5ad4c commit: 77c4a4d2cb63d8e7c95840c44f5bf9b597316120 Author: Zac Medico gentoo org> AuthorDate: Mon Nov 17 16:57:23 2014 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Nov 17 17:41:15 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=77c4a4d2 unprivileged mode: fix cross-prefix support In commit 1364fcd89384c9f60e6d72d7057dc00d8caba175, EROOT calculation in portage.data did not account for cross-prefix support. This is fixed by using new _target_root and _target_eprefix functions to perform the calculation. The _target_eprefix function is also useful in portageq, where the target EPREFIX needs to be known before portage.settings is instantiated. Fixes 1364fcd89384 ("Support unprivileged mode for bug #433453.") Acked-by: Brian Dolbec gentoo.org> --- bin/portageq | 4 +--- pym/portage/data.py | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/bin/portageq b/bin/portageq index ef565d1..6a42bfd 100755 --- a/bin/portageq +++ b/bin/portageq @@ -1397,9 +1397,7 @@ def main(argv): # portage.settings["EPREFIX"] here, but that would force # instantiation of portage.settings, which we don't want to do # until after we've calculated ROOT (see bug #529200). - eprefix = os.environ.get("EPREFIX", portage.const.EPREFIX) - if eprefix: - eprefix = portage.util.normalize_path(eprefix) + eprefix = portage.data._target_eprefix() eroot = portage.util.normalize_path(argv[2]) if eprefix: diff --git a/pym/portage/data.py b/pym/portage/data.py index d9b36ee..2fd287d 100644 --- a/pym/portage/data.py +++ b/pym/portage/data.py @@ -35,6 +35,35 @@ if not lchown: lchown = portage._unicode_func_wrapper(lchown) +def _target_eprefix(): + """ + Calculate the target EPREFIX, which may be different from + portage.const.EPREFIX due to cross-prefix support. The result + is equivalent to portage.settings["EPREFIX"], but the calculation + is done without the expense of instantiating portage.settings. + @rtype: str + @return: the target EPREFIX + """ + eprefix = os.environ.get("EPREFIX", portage.const.EPREFIX) + if eprefix: + eprefix = portage.util.normalize_path(eprefix) + return eprefix + +def _target_root(): + """ + Calculate the target ROOT. The result is equivalent to + portage.settings["ROOT"], but the calculation + is done without the expense of instantiating portage.settings. + @rtype: str + @return: the target ROOT (always ends with a slash) + """ + root = os.environ.get("ROOT") + if not root: + # Handle either empty or unset ROOT. + root = os.sep + root = portage.util.normalize_path(root) + return root.rstrip(os.sep) + os.sep + def portage_group_warning(): warn_prefix = colorize("BAD", "*** WARNING *** ") mylines = [ @@ -96,8 +125,7 @@ def _get_global(k): # The config class has equivalent code, but we also need to # do it here if _disable_legacy_globals() has been called. eroot_or_parent = first_existing(os.path.join( - os.environ.get('ROOT', os.sep), - portage.const.EPREFIX.lstrip(os.sep))) + _target_root(), _target_eprefix().lstrip(os.sep))) try: eroot_st = os.stat(eroot_or_parent) except OSError: @@ -210,8 +238,7 @@ def _get_global(k): # The config class has equivalent code, but we also need to # do it here if _disable_legacy_globals() has been called. eroot_or_parent = first_existing(os.path.join( - os.environ.get('ROOT', os.sep), - portage.const.EPREFIX.lstrip(os.sep))) + _target_root(), _target_eprefix().lstrip(os.sep))) try: eroot_st = os.stat(eroot_or_parent) except OSError: