1 |
For unprivileged mode, if PORTAGE_DEPCACHEDIR is unset and the default |
2 |
PORTAGE_DEPCACHEDIR setting does not refer to a writable directory |
3 |
(or there are not sufficient permissions to create it), then |
4 |
automatically make PORTAGE_DEPCACHEDIR relative to the current target |
5 |
root (which should always be writable for unprivileged mode). Also, in |
6 |
create_trees, propagate the automatically generated PORTAGE_DEPCACHEDIR |
7 |
setting to the config instance that is instantiated for ROOT = "/". |
8 |
|
9 |
The result is that unprivileged mode will get a writable |
10 |
PORTAGE_DEPCACHEDIR by default, and the default can be overridden by |
11 |
setting the PORTAGE_DEPCACHEDIR variable. |
12 |
|
13 |
Fixes: 1364fcd89384 ("Support unprivileged mode for bug #433453.") |
14 |
X-Gentoo-Bug: 433453 |
15 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=433453 |
16 |
--- |
17 |
pym/portage/__init__.py | 3 +++ |
18 |
pym/portage/package/ebuild/config.py | 37 ++++++++++++++++++++++++++---------- |
19 |
2 files changed, 30 insertions(+), 10 deletions(-) |
20 |
|
21 |
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py |
22 |
index 66bfeb0..d8046f3 100644 |
23 |
--- a/pym/portage/__init__.py |
24 |
+++ b/pym/portage/__init__.py |
25 |
@@ -570,6 +570,7 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None, |
26 |
env=env, eprefix=eprefix) |
27 |
settings.lock() |
28 |
|
29 |
+ depcachedir = settings.get('PORTAGE_DEPCACHEDIR') |
30 |
trees._target_eroot = settings['EROOT'] |
31 |
myroots = [(settings['EROOT'], settings)] |
32 |
if settings["ROOT"] == "/" and settings["EPREFIX"] == const.EPREFIX: |
33 |
@@ -587,6 +588,8 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None, |
34 |
v = settings.get(k) |
35 |
if v is not None: |
36 |
clean_env[k] = v |
37 |
+ if depcachedir is not None: |
38 |
+ clean_env['PORTAGE_DEPCACHEDIR'] = depcachedir |
39 |
settings = config(config_root=None, target_root="/", |
40 |
env=clean_env, eprefix=None) |
41 |
settings.lock() |
42 |
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py |
43 |
index 2ceb122..1ce5175 100644 |
44 |
--- a/pym/portage/package/ebuild/config.py |
45 |
+++ b/pym/portage/package/ebuild/config.py |
46 |
@@ -8,6 +8,7 @@ __all__ = [ |
47 |
] |
48 |
|
49 |
import copy |
50 |
+import errno |
51 |
from itertools import chain |
52 |
import grp |
53 |
import logging |
54 |
@@ -826,16 +827,6 @@ class config(object): |
55 |
if "USE_ORDER" not in self: |
56 |
self.backupenv["USE_ORDER"] = "env:pkg:conf:defaults:pkginternal:repo:env.d" |
57 |
|
58 |
- self.depcachedir = DEPCACHE_PATH |
59 |
- if portage.const.EPREFIX: |
60 |
- self.depcachedir = os.path.join(portage.const.EPREFIX, |
61 |
- DEPCACHE_PATH.lstrip(os.sep)) |
62 |
- |
63 |
- if self.get("PORTAGE_DEPCACHEDIR", None): |
64 |
- self.depcachedir = self["PORTAGE_DEPCACHEDIR"] |
65 |
- self["PORTAGE_DEPCACHEDIR"] = self.depcachedir |
66 |
- self.backup_changes("PORTAGE_DEPCACHEDIR") |
67 |
- |
68 |
if "CBUILD" not in self and "CHOST" in self: |
69 |
self["CBUILD"] = self["CHOST"] |
70 |
self.backup_changes("CBUILD") |
71 |
@@ -898,6 +889,32 @@ class config(object): |
72 |
self[var] = default_val |
73 |
self.backup_changes(var) |
74 |
|
75 |
+ self.depcachedir = self.get("PORTAGE_DEPCACHEDIR") |
76 |
+ if self.depcachedir is None: |
77 |
+ self.depcachedir = os.path.join(os.sep, |
78 |
+ portage.const.EPREFIX, DEPCACHE_PATH.lstrip(os.sep)) |
79 |
+ if unprivileged and target_root != os.sep: |
80 |
+ # In unprivileged mode, automatically make |
81 |
+ # depcachedir relative to target_root if the |
82 |
+ # default depcachedir is not writable. |
83 |
+ current_dir = self.depcachedir |
84 |
+ while current_dir != os.sep: |
85 |
+ try: |
86 |
+ st = os.stat(current_dir) |
87 |
+ except OSError as e: |
88 |
+ if errno == errno.ENOENT: |
89 |
+ current_dir = \ |
90 |
+ os.path.dirname(current_dir) |
91 |
+ continue |
92 |
+ break |
93 |
+ |
94 |
+ if not os.access(current_dir, os.W_OK): |
95 |
+ self.depcachedir = os.path.join(eroot, |
96 |
+ DEPCACHE_PATH.lstrip(os.sep)) |
97 |
+ |
98 |
+ self["PORTAGE_DEPCACHEDIR"] = self.depcachedir |
99 |
+ self.backup_changes("PORTAGE_DEPCACHEDIR") |
100 |
+ |
101 |
if portage._internal_caller: |
102 |
self["PORTAGE_INTERNAL_CALLER"] = "1" |
103 |
self.backup_changes("PORTAGE_INTERNAL_CALLER") |
104 |
-- |
105 |
2.0.4 |