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.

== Review notes ==
This is the final version that actually works ;-). I did a full egencache
run with it and the only packages that fail are eblit users (all of them
have bugs open with deadline 1 week from now). There might be a few more
silly failures, so I'll test it for a while, and ask Toralf to possibly
do some tinderboxing.

---
 man/ebuild.5                                     |  6 +++---
 pym/_emerge/EbuildPhase.py                       |  4 +++-
 pym/portage/package/ebuild/config.py             |  3 ---
 pym/portage/package/ebuild/doebuild.py           |  6 +++++-
 pym/portage/package/ebuild/prepare_build_dirs.py | 13 +++++++++++++
 5 files changed, 24 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 fc185fcfd..504c812ea 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:
@@ -229,6 +230,7 @@ class EbuildPhase(CompositeTask):
                        # ownership since tar can change that too.
                        os.utime(settings["WORKDIR"], None)
                        _prepare_workdir(settings)
+                       _prepare_fake_filesdir(settings)
                elif self.phase == "install":
                        out = io.StringIO()
                        _post_src_install_write_metadata(settings)
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..2f80a28ee 100644
--- a/pym/portage/package/ebuild/doebuild.py
+++ b/pym/portage/package/ebuild/doebuild.py
@@ -31,6 +31,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
        'portage.package.ebuild.digestcheck:digestcheck',
        'portage.package.ebuild.digestgen:digestgen',
        'portage.package.ebuild.fetch:fetch',
+       'portage.package.ebuild.prepare_build_dirs:_prepare_fake_filesdir',
        'portage.package.ebuild._ipc.QueryCommand:QueryCommand',
        'portage.dep._slot_operator:evaluate_slot_operator_equal_deps',
        'portage.package.ebuild._spawn_nofetch:spawn_nofetch',
@@ -164,6 +165,9 @@ def _doebuild_spawn(phase, settings, actionmap=None, 
**kwargs):
                        os.path.basename(EBUILD_SH_BINARY))),
                        ebuild_sh_arg)
 
+       if phase == 'unpack':
+               _prepare_fake_filesdir(settings)
+
        settings['EBUILD_PHASE'] = phase
        try:
                return spawn(cmd, settings, **kwargs)
@@ -337,7 +341,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 +393,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)
-- 
2.12.0


Reply via email to