aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2016-06-04 20:23:53 +0200
committerMichał Górny <mgorny@gentoo.org>2017-03-24 20:41:01 +0100
commit0637c95545ab7dc0bb5d091de221b9e99e2cf5b2 (patch)
tree9fe8c7a4116abab449432406ecec77dbcb907990
parentDisplay network-sandbox* FEATURES before setup phase (diff)
downloadportage-0637c95545ab7dc0bb5d091de221b9e99e2cf5b2.tar.gz
portage-0637c95545ab7dc0bb5d091de221b9e99e2cf5b2.tar.bz2
portage-0637c95545ab7dc0bb5d091de221b9e99e2cf5b2.zip
portage.package.ebuild: Use a fake FILESDIR to catch invalid accesses
Use a model of fake FILESDIR path to ensure that invalid accesses to FILESDIR will result in failures rather than being silently allowed by Portage. This mostly involves accesses in the global scope and pkg_* phases, although the current model does not cover the latter completely (i.e. does not guarantee that the directory is removed post src_*). This model aims to follow PMS wording quite precisely. The value of FILESDIR is meant to be stable throughout the build process, and it is reliably set to a temporary directory path. However, since the path is not guaranteed to be present outside src_*, the directory symlink is not actually created before src_* phases. Reviewed-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--man/ebuild.56
-rw-r--r--pym/_emerge/EbuildPhase.py6
-rw-r--r--pym/portage/package/ebuild/config.py3
-rw-r--r--pym/portage/package/ebuild/doebuild.py2
-rw-r--r--pym/portage/package/ebuild/prepare_build_dirs.py13
5 files changed, 22 insertions, 8 deletions
diff --git a/man/ebuild.5 b/man/ebuild.5
index 72b8b6905..e4c866cd2 100644
--- a/man/ebuild.5
+++ b/man/ebuild.5
@@ -411,9 +411,9 @@ not be defined. It is autogenerated from the \fBSRC_URI\fR variable.
.B WORKDIR\fR = \fI"${PORTAGE_TMPDIR}/portage/${CATEGORY}/${PF}/work"
Contains the path to the package build root. Do not modify this variable.
.TP
-.B FILESDIR\fR = \fI"${repository_location}/${CATEGORY}/${PN}/files"
-Contains the path to the 'files' subdirectory in the package specific
-location in given repository. Do not modify this variable.
+.B FILESDIR\fR = \fI"${PORTAGE_TMPDIR}/${CATEGORY}/${PF}/files"
+Contains the path to the directory in which package-specific auxiliary
+files are located. Do not modify this variable.
.TP
.B EBUILD_PHASE
Contains the abreviated name of the phase function that is
diff --git a/pym/_emerge/EbuildPhase.py b/pym/_emerge/EbuildPhase.py
index 6191ee2b3..aa3a66831 100644
--- a/pym/_emerge/EbuildPhase.py
+++ b/pym/_emerge/EbuildPhase.py
@@ -11,7 +11,8 @@ from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor
from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
from _emerge.EbuildProcess import EbuildProcess
from _emerge.CompositeTask import CompositeTask
-from portage.package.ebuild.prepare_build_dirs import _prepare_workdir
+from portage.package.ebuild.prepare_build_dirs import (_prepare_workdir,
+ _prepare_fake_filesdir)
from portage.util import writemsg
try:
@@ -169,6 +170,9 @@ class EbuildPhase(CompositeTask):
def _start_ebuild(self):
+ if self.phase == "unpack":
+ _prepare_fake_filesdir(self.settings)
+
fd_pipes = self.fd_pipes
if fd_pipes is None:
if not self.background and self.phase == 'nofetch':
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py
index ef29afeab..f8043dbf5 100644
--- a/pym/portage/package/ebuild/config.py
+++ b/pym/portage/package/ebuild/config.py
@@ -2784,9 +2784,6 @@ class config(object):
mydict.pop("EPREFIX", None)
mydict.pop("EROOT", None)
- if phase == 'depend':
- mydict.pop('FILESDIR', None)
-
if phase not in ("pretend", "setup", "preinst", "postinst") or \
not eapi_exports_replace_vars(eapi):
mydict.pop("REPLACING_VERSIONS", None)
diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py
index 4baae17b1..e7db54bcf 100644
--- a/pym/portage/package/ebuild/doebuild.py
+++ b/pym/portage/package/ebuild/doebuild.py
@@ -337,7 +337,6 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
mysettings["EBUILD"] = ebuild_path
mysettings["O"] = pkg_dir
mysettings.configdict["pkg"]["CATEGORY"] = cat
- mysettings["FILESDIR"] = pkg_dir+"/files"
mysettings["PF"] = mypv
if hasattr(mydbapi, 'repositories'):
@@ -390,6 +389,7 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
mysettings["WORKDIR"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "work")
mysettings["D"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image") + os.sep
mysettings["T"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "temp")
+ mysettings["FILESDIR"] = os.path.join(settings["PORTAGE_BUILDDIR"], "files")
# Prefix forward compatability
eprefix_lstrip = mysettings["EPREFIX"].lstrip(os.sep)
diff --git a/pym/portage/package/ebuild/prepare_build_dirs.py b/pym/portage/package/ebuild/prepare_build_dirs.py
index 7e5249b66..e3ae318bd 100644
--- a/pym/portage/package/ebuild/prepare_build_dirs.py
+++ b/pym/portage/package/ebuild/prepare_build_dirs.py
@@ -396,3 +396,16 @@ def _ensure_log_subdirs(logdir, subdir):
while subdir_split:
current = os.path.join(current, subdir_split.pop())
ensure_dirs(current, uid=uid, gid=gid, mode=grp_mode, mask=0)
+
+def _prepare_fake_filesdir(settings):
+ real_filesdir = settings["O"]+"/files"
+ symlink_path = settings["FILESDIR"]
+
+ try:
+ link_target = os.readlink(symlink_path)
+ except OSError:
+ os.symlink(real_filesdir, symlink_path)
+ else:
+ if link_target != real_filesdir:
+ os.unlink(symlink_path)
+ os.symlink(real_filesdir, symlink_path)