public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
Date: Mon, 17 Nov 2014 17:43:54 +0000 (UTC)	[thread overview]
Message-ID: <1416246075.77c4a4d2cb63d8e7c95840c44f5bf9b597316120.zmedico@gentoo> (raw)

commit:     77c4a4d2cb63d8e7c95840c44f5bf9b597316120
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 17 16:57:23 2014 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> 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 <dolsen <AT> 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:


             reply	other threads:[~2014-11-17 17:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-17 17:43 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-11-29 23:24 [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/ Mike Frysinger
2013-06-25  7:48 Zac Medico
2013-06-23 22:57 Zac Medico
2013-06-23 22:40 Zac Medico
2013-02-11  9:39 Zac Medico
2013-01-19  5:16 Zac Medico
2013-01-19  5:00 Zac Medico
2013-01-19  3:23 Zac Medico
2013-01-19  3:23 Zac Medico
2013-01-19  2:27 Zac Medico
2013-01-19  1:53 Zac Medico
2012-10-18  0:05 Zac Medico
2012-03-17 16:44 Zac Medico
2012-03-11  1:40 Mike Frysinger
2011-12-08  7:26 Zac Medico
2011-06-17 22:35 Zac Medico
2011-06-04  1:39 Zac Medico
2011-02-20  0:00 Zac Medico

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=1416246075.77c4a4d2cb63d8e7c95840c44f5bf9b597316120.zmedico@gentoo \
    --to=zmedico@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: link
Be 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