1 |
In commit 1364fcd89384c9f60e6d72d7057dc00d8caba175, EROOT calculation |
2 |
in portage.data did not account from cross-prefix support. This is |
3 |
fixed by using new _target_root and _target_eprefix functions to |
4 |
perform the calculation. The _target_eprefix function is also useful |
5 |
in portageq, where the target EPREFIX needs to be known before |
6 |
portage.settings is instantiated. |
7 |
|
8 |
Fixes 1364fcd89384 ("Support unprivileged mode for bug #433453.") |
9 |
--- |
10 |
bin/portageq | 4 +--- |
11 |
pym/portage/data.py | 35 +++++++++++++++++++++++++++++++---- |
12 |
2 files changed, 32 insertions(+), 7 deletions(-) |
13 |
|
14 |
diff --git a/bin/portageq b/bin/portageq |
15 |
index ef565d1..6a42bfd 100755 |
16 |
--- a/bin/portageq |
17 |
+++ b/bin/portageq |
18 |
@@ -1397,9 +1397,7 @@ def main(argv): |
19 |
# portage.settings["EPREFIX"] here, but that would force |
20 |
# instantiation of portage.settings, which we don't want to do |
21 |
# until after we've calculated ROOT (see bug #529200). |
22 |
- eprefix = os.environ.get("EPREFIX", portage.const.EPREFIX) |
23 |
- if eprefix: |
24 |
- eprefix = portage.util.normalize_path(eprefix) |
25 |
+ eprefix = portage.data._target_eprefix() |
26 |
eroot = portage.util.normalize_path(argv[2]) |
27 |
|
28 |
if eprefix: |
29 |
diff --git a/pym/portage/data.py b/pym/portage/data.py |
30 |
index d9b36ee..2fd287d 100644 |
31 |
--- a/pym/portage/data.py |
32 |
+++ b/pym/portage/data.py |
33 |
@@ -35,6 +35,35 @@ if not lchown: |
34 |
|
35 |
lchown = portage._unicode_func_wrapper(lchown) |
36 |
|
37 |
+def _target_eprefix(): |
38 |
+ """ |
39 |
+ Calculate the target EPREFIX, which may be different from |
40 |
+ portage.const.EPREFIX due to cross-prefix support. The result |
41 |
+ is equivalent to portage.settings["EPREFIX"], but the calculation |
42 |
+ is done without the expense of instantiating portage.settings. |
43 |
+ @rtype: str |
44 |
+ @return: the target EPREFIX |
45 |
+ """ |
46 |
+ eprefix = os.environ.get("EPREFIX", portage.const.EPREFIX) |
47 |
+ if eprefix: |
48 |
+ eprefix = portage.util.normalize_path(eprefix) |
49 |
+ return eprefix |
50 |
+ |
51 |
+def _target_root(): |
52 |
+ """ |
53 |
+ Calculate the target ROOT. The result is equivalent to |
54 |
+ portage.settings["ROOT"], but the calculation |
55 |
+ is done without the expense of instantiating portage.settings. |
56 |
+ @rtype: str |
57 |
+ @return: the target ROOT (always ends with a slash) |
58 |
+ """ |
59 |
+ root = os.environ.get("ROOT") |
60 |
+ if not root: |
61 |
+ # Handle either empty or unset ROOT. |
62 |
+ root = os.sep |
63 |
+ root = portage.util.normalize_path(root) |
64 |
+ return root.rstrip(os.sep) + os.sep |
65 |
+ |
66 |
def portage_group_warning(): |
67 |
warn_prefix = colorize("BAD", "*** WARNING *** ") |
68 |
mylines = [ |
69 |
@@ -96,8 +125,7 @@ def _get_global(k): |
70 |
# The config class has equivalent code, but we also need to |
71 |
# do it here if _disable_legacy_globals() has been called. |
72 |
eroot_or_parent = first_existing(os.path.join( |
73 |
- os.environ.get('ROOT', os.sep), |
74 |
- portage.const.EPREFIX.lstrip(os.sep))) |
75 |
+ _target_root(), _target_eprefix().lstrip(os.sep))) |
76 |
try: |
77 |
eroot_st = os.stat(eroot_or_parent) |
78 |
except OSError: |
79 |
@@ -210,8 +238,7 @@ def _get_global(k): |
80 |
# The config class has equivalent code, but we also need to |
81 |
# do it here if _disable_legacy_globals() has been called. |
82 |
eroot_or_parent = first_existing(os.path.join( |
83 |
- os.environ.get('ROOT', os.sep), |
84 |
- portage.const.EPREFIX.lstrip(os.sep))) |
85 |
+ _target_root(), _target_eprefix().lstrip(os.sep))) |
86 |
try: |
87 |
eroot_st = os.stat(eroot_or_parent) |
88 |
except OSError: |
89 |
-- |
90 |
2.0.4 |