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: