From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id EFB0B138825 for ; Sun, 9 Nov 2014 23:24:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C371FE0888; Sun, 9 Nov 2014 23:24:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3975FE081E for ; Sun, 9 Nov 2014 23:24:51 +0000 (UTC) Received: from localhost.localdomain (ip70-181-96-121.oc.oc.cox.net [70.181.96.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: zmedico) by smtp.gentoo.org (Postfix) with ESMTPSA id 0F80133EEAE; Sun, 9 Nov 2014 23:24:50 +0000 (UTC) From: Zac Medico To: gentoo-portage-dev@lists.gentoo.org Cc: Zac Medico Subject: [gentoo-portage-dev] [PATCH] unprivileged mode: generate PORTAGE_DEPCACHEDIR Date: Sun, 9 Nov 2014 15:24:40 -0800 Message-Id: <1415575480-19505-1-git-send-email-zmedico@gentoo.org> X-Mailer: git-send-email 2.0.4 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: 5f9de9b2-4e21-40c8-a645-c4ee711db908 X-Archives-Hash: cb8aa4e8b62b1db425ab813ebf82ec6b 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