Skip to content

Commit

Permalink
unprivileged mode: generate PORTAGE_DEPCACHEDIR
Browse files Browse the repository at this point in the history
For unprivileged mode, if PORTAGE_DEPCACHEDIR is unset and the default
PORTAGE_DEPCACHEDIR setting does not refer to a writable directory
(or there are not sufficient permissions to create it), then
automatically make PORTAGE_DEPCACHEDIR relative to the current target
root (which should always be writable for unprivileged mode). Also, in
create_trees, propagate the automatically generated PORTAGE_DEPCACHEDIR
setting to the config instance that is instantiated for ROOT = "/".

The result is that unprivileged mode will get a writable
PORTAGE_DEPCACHEDIR by default, and the default can be overridden by
setting the PORTAGE_DEPCACHEDIR variable.

Fixes: 1364fcd ("Support unprivileged mode for bug #433453.")
X-Gentoo-Bug: 433453
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=433453
Acked-by: Alexander Berntsen <bernalex@gentoo.org>
  • Loading branch information
zmedico committed Nov 15, 2014
1 parent 9f6967d commit 690b9de
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
3 changes: 3 additions & 0 deletions pym/portage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None,
env=env, eprefix=eprefix)
settings.lock()

depcachedir = settings.get('PORTAGE_DEPCACHEDIR')
trees._target_eroot = settings['EROOT']
myroots = [(settings['EROOT'], settings)]
if settings["ROOT"] == "/" and settings["EPREFIX"] == const.EPREFIX:
Expand All @@ -587,6 +588,8 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None,
v = settings.get(k)
if v is not None:
clean_env[k] = v
if depcachedir is not None:
clean_env['PORTAGE_DEPCACHEDIR'] = depcachedir
settings = config(config_root=None, target_root="/",
env=clean_env, eprefix=None)
settings.lock()
Expand Down
39 changes: 29 additions & 10 deletions pym/portage/package/ebuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
]

import copy
import errno
from itertools import chain
import grp
import logging
Expand Down Expand Up @@ -826,16 +827,6 @@ def __init__(self, clone=None, mycpv=None, config_profile_path=None,
if "USE_ORDER" not in self:
self.backupenv["USE_ORDER"] = "env:pkg:conf:defaults:pkginternal:repo:env.d"

self.depcachedir = DEPCACHE_PATH
if portage.const.EPREFIX:
self.depcachedir = os.path.join(portage.const.EPREFIX,
DEPCACHE_PATH.lstrip(os.sep))

if self.get("PORTAGE_DEPCACHEDIR", None):
self.depcachedir = self["PORTAGE_DEPCACHEDIR"]
self["PORTAGE_DEPCACHEDIR"] = self.depcachedir
self.backup_changes("PORTAGE_DEPCACHEDIR")

if "CBUILD" not in self and "CHOST" in self:
self["CBUILD"] = self["CHOST"]
self.backup_changes("CBUILD")
Expand Down Expand Up @@ -898,6 +889,34 @@ def __init__(self, clone=None, mycpv=None, config_profile_path=None,
self[var] = default_val
self.backup_changes(var)

self.depcachedir = self.get("PORTAGE_DEPCACHEDIR")
if self.depcachedir is None:
self.depcachedir = os.path.join(os.sep,
portage.const.EPREFIX, DEPCACHE_PATH.lstrip(os.sep))
if unprivileged and target_root != os.sep:
# In unprivileged mode, automatically make
# depcachedir relative to target_root if the
# default depcachedir is not writable.
current_dir = self.depcachedir
found_dir = False
while current_dir != os.sep and not found_dir:
try:
os.stat(current_dir)
found_dir = True
except OSError as e:
if e.errno == errno.ENOENT:
current_dir = os.path.dirname(
current_dir)
else:
found_dir = True

if not os.access(current_dir, os.W_OK):
self.depcachedir = os.path.join(eroot,
DEPCACHE_PATH.lstrip(os.sep))

self["PORTAGE_DEPCACHEDIR"] = self.depcachedir
self.backup_changes("PORTAGE_DEPCACHEDIR")

if portage._internal_caller:
self["PORTAGE_INTERNAL_CALLER"] = "1"
self.backup_changes("PORTAGE_INTERNAL_CALLER")
Expand Down

0 comments on commit 690b9de

Please sign in to comment.