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 |
This updated patch avoids use of continue and break in the loop that |
18 |
checks for writable depcachedir, as requested by Alexander Berntsen. |
19 |
|
20 |
pym/portage/__init__.py | 3 +++ |
21 |
pym/portage/package/ebuild/config.py | 39 +++++++++++++++++++++++++++--------- |
22 |
2 files changed, 32 insertions(+), 10 deletions(-) |
23 |
|
24 |
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py |
25 |
index 66bfeb0..d8046f3 100644 |
26 |
--- a/pym/portage/__init__.py |
27 |
+++ b/pym/portage/__init__.py |
28 |
@@ -570,6 +570,7 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None, |
29 |
env=env, eprefix=eprefix) |
30 |
settings.lock() |
31 |
|
32 |
+ depcachedir = settings.get('PORTAGE_DEPCACHEDIR') |
33 |
trees._target_eroot = settings['EROOT'] |
34 |
myroots = [(settings['EROOT'], settings)] |
35 |
if settings["ROOT"] == "/" and settings["EPREFIX"] == const.EPREFIX: |
36 |
@@ -587,6 +588,8 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None, |
37 |
v = settings.get(k) |
38 |
if v is not None: |
39 |
clean_env[k] = v |
40 |
+ if depcachedir is not None: |
41 |
+ clean_env['PORTAGE_DEPCACHEDIR'] = depcachedir |
42 |
settings = config(config_root=None, target_root="/", |
43 |
env=clean_env, eprefix=None) |
44 |
settings.lock() |
45 |
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py |
46 |
index 2ceb122..a17a6b3 100644 |
47 |
--- a/pym/portage/package/ebuild/config.py |
48 |
+++ b/pym/portage/package/ebuild/config.py |
49 |
@@ -8,6 +8,7 @@ __all__ = [ |
50 |
] |
51 |
|
52 |
import copy |
53 |
+import errno |
54 |
from itertools import chain |
55 |
import grp |
56 |
import logging |
57 |
@@ -826,16 +827,6 @@ class config(object): |
58 |
if "USE_ORDER" not in self: |
59 |
self.backupenv["USE_ORDER"] = "env:pkg:conf:defaults:pkginternal:repo:env.d" |
60 |
|
61 |
- self.depcachedir = DEPCACHE_PATH |
62 |
- if portage.const.EPREFIX: |
63 |
- self.depcachedir = os.path.join(portage.const.EPREFIX, |
64 |
- DEPCACHE_PATH.lstrip(os.sep)) |
65 |
- |
66 |
- if self.get("PORTAGE_DEPCACHEDIR", None): |
67 |
- self.depcachedir = self["PORTAGE_DEPCACHEDIR"] |
68 |
- self["PORTAGE_DEPCACHEDIR"] = self.depcachedir |
69 |
- self.backup_changes("PORTAGE_DEPCACHEDIR") |
70 |
- |
71 |
if "CBUILD" not in self and "CHOST" in self: |
72 |
self["CBUILD"] = self["CHOST"] |
73 |
self.backup_changes("CBUILD") |
74 |
@@ -898,6 +889,34 @@ class config(object): |
75 |
self[var] = default_val |
76 |
self.backup_changes(var) |
77 |
|
78 |
+ self.depcachedir = self.get("PORTAGE_DEPCACHEDIR") |
79 |
+ if self.depcachedir is None: |
80 |
+ self.depcachedir = os.path.join(os.sep, |
81 |
+ portage.const.EPREFIX, DEPCACHE_PATH.lstrip(os.sep)) |
82 |
+ if unprivileged and target_root != os.sep: |
83 |
+ # In unprivileged mode, automatically make |
84 |
+ # depcachedir relative to target_root if the |
85 |
+ # default depcachedir is not writable. |
86 |
+ current_dir = self.depcachedir |
87 |
+ found_dir = False |
88 |
+ while current_dir != os.sep and not found_dir: |
89 |
+ try: |
90 |
+ os.stat(current_dir) |
91 |
+ found_dir = True |
92 |
+ except OSError as e: |
93 |
+ if e.errno == errno.ENOENT: |
94 |
+ current_dir = \ |
95 |
+ os.path.dirname(current_dir) |
96 |
+ else: |
97 |
+ found_dir = True |
98 |
+ |
99 |
+ if not os.access(current_dir, os.W_OK): |
100 |
+ self.depcachedir = os.path.join(eroot, |
101 |
+ DEPCACHE_PATH.lstrip(os.sep)) |
102 |
+ |
103 |
+ self["PORTAGE_DEPCACHEDIR"] = self.depcachedir |
104 |
+ self.backup_changes("PORTAGE_DEPCACHEDIR") |
105 |
+ |
106 |
if portage._internal_caller: |
107 |
self["PORTAGE_INTERNAL_CALLER"] = "1" |
108 |
self.backup_changes("PORTAGE_INTERNAL_CALLER") |
109 |
-- |
110 |
2.0.4 |