From 0c217d51685bde5085607a8b54e8507b3624c36e Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 9 Dec 2011 14:36:12 -0800 Subject: [PATCH] Auto-generate PORTAGE_INST_GID/UID for prefix. For prefix environments, default to the UID and GID of the top-level EROOT directory. This allows us to avoid using hardcoded defaults. It's still possible to override these variables via make.conf. --- cnf/make.globals | 4 ---- pym/portage/package/ebuild/config.py | 24 ++++++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cnf/make.globals b/cnf/make.globals index e1243fb08..cd06fdcea 100644 --- a/cnf/make.globals +++ b/cnf/make.globals @@ -111,10 +111,6 @@ CONFIG_PROTECT_MASK="/etc/env.d" # Disable auto-use USE_ORDER="env:pkg:conf:defaults:pkginternal:repo:env.d" -# Default ownership of installed files. -PORTAGE_INST_UID="0" -PORTAGE_INST_GID="0" - # Mode bits for ${WORKDIR} (see ebuild.5). PORTAGE_WORKDIR_MODE="0700" diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 53a625bc3..bf33978e2 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -723,14 +723,30 @@ class config(object): self["USERLAND"] = "GNU" self.backup_changes("USERLAND") - for var in ("PORTAGE_INST_UID", "PORTAGE_INST_GID"): + default_inst_ids = { + "PORTAGE_INST_GID": "0", + "PORTAGE_INST_UID": "0", + } + + if eprefix: + # For prefix environments, default to the UID and GID of + # the top-level EROOT directory. + try: + eroot_st = os.stat(eroot) + except OSError: + pass + else: + default_inst_ids["PORTAGE_INST_GID"] = str(eroot_st.st_gid) + default_inst_ids["PORTAGE_INST_UID"] = str(eroot_st.st_uid) + + for var, default_val in default_inst_ids.items(): try: - self[var] = str(int(self.get(var, "0"))) + self[var] = str(int(self.get(var, default_val))) except ValueError: writemsg(_("!!! %s='%s' is not a valid integer. " - "Falling back to '0'.\n") % (var, self[var]), + "Falling back to %s.\n") % (var, self[var], default_val), noiselevel=-1) - self[var] = "0" + self[var] = default_val self.backup_changes(var) # initialize self.features -- 2.26.2