public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: pym/_emerge/, pym/portage/package/ebuild/, man/
@ 2017-03-24 19:41 Michał Górny
  0 siblings, 0 replies; only message in thread
From: Michał Górny @ 2017-03-24 19:41 UTC (permalink / raw
  To: gentoo-commits

commit:     0637c95545ab7dc0bb5d091de221b9e99e2cf5b2
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Jun  4 18:23:53 2016 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Mar 24 19:41:01 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=0637c955

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 <AT> gentoo.org>

 man/ebuild.5                                     |  6 +++---
 pym/_emerge/EbuildPhase.py                       |  6 +++++-
 pym/portage/package/ebuild/config.py             |  3 ---
 pym/portage/package/ebuild/doebuild.py           |  2 +-
 pym/portage/package/ebuild/prepare_build_dirs.py | 13 +++++++++++++
 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)


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-03-24 19:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-24 19:41 [gentoo-commits] proj/portage:master commit in: pym/_emerge/, pym/portage/package/ebuild/, man/ Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox