From: Zac Medico <zmedico@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Zac Medico <zmedico@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH] unprivileged mode: generate PORTAGE_DEPCACHEDIR
Date: Sun, 9 Nov 2014 15:24:40 -0800 [thread overview]
Message-ID: <1415575480-19505-1-git-send-email-zmedico@gentoo.org> (raw)
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: 1364fcd89384 ("Support unprivileged mode for bug #433453.")
X-Gentoo-Bug: 433453
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=433453
---
pym/portage/__init__.py | 3 +++
pym/portage/package/ebuild/config.py | 37 ++++++++++++++++++++++++++----------
2 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 66bfeb0..d8046f3 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -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:
@@ -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()
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py
index 2ceb122..1ce5175 100644
--- a/pym/portage/package/ebuild/config.py
+++ b/pym/portage/package/ebuild/config.py
@@ -8,6 +8,7 @@ __all__ = [
]
import copy
+import errno
from itertools import chain
import grp
import logging
@@ -826,16 +827,6 @@ class config(object):
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")
@@ -898,6 +889,32 @@ class config(object):
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
+ while current_dir != os.sep:
+ try:
+ st = os.stat(current_dir)
+ except OSError as e:
+ if errno == errno.ENOENT:
+ current_dir = \
+ os.path.dirname(current_dir)
+ continue
+ break
+
+ 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")
--
2.0.4
next reply other threads:[~2014-11-09 23:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-09 23:24 Zac Medico [this message]
2014-11-10 4:58 ` [gentoo-portage-dev] Re: [PATCH] unprivileged mode: generate PORTAGE_DEPCACHEDIR Duncan
2014-11-10 5:28 ` Zac Medico
2014-11-10 6:06 ` Duncan
2014-11-10 11:09 ` [gentoo-portage-dev] " Alexander Berntsen
2014-11-10 18:21 ` Zac Medico
2014-11-10 20:32 ` Alexander Berntsen
2014-11-11 0:17 ` Zac Medico
2014-11-11 9:14 ` Alexander Berntsen
2014-11-15 5:19 ` Zac Medico
2014-11-15 7:21 ` [gentoo-portage-dev] [PATCH] unprivileged mode: use first_existing helper func Zac Medico
2014-11-17 8:12 ` Alexander Berntsen
2014-11-10 20:48 ` [gentoo-portage-dev] [PATCH v2] unprivileged mode: generate PORTAGE_DEPCACHEDIR Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415575480-19505-1-git-send-email-zmedico@gentoo.org \
--to=zmedico@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox