1 |
Use a model of fake FILESDIR path to ensure that invalid accesses to |
2 |
FILESDIR will result in failures rather than being silently allowed by |
3 |
Portage. This mostly involves accesses in the global scope and pkg_* |
4 |
phases, although the current model does not cover the latter completely |
5 |
(i.e. does not guarantee that the directory is removed post src_*). |
6 |
|
7 |
This model aims to follow PMS wording quite precisely. The value of |
8 |
FILESDIR is meant to be stable throughout the build process, and it is |
9 |
reliably set to a temporary directory path. However, since the path is |
10 |
not guaranteed to be present outside src_*, the directory symlink is not |
11 |
actually created before src_* phases. |
12 |
--- |
13 |
man/ebuild.5 | 6 +++--- |
14 |
pym/_emerge/EbuildPhase.py | 6 +++++- |
15 |
pym/portage/package/ebuild/config.py | 3 --- |
16 |
pym/portage/package/ebuild/doebuild.py | 2 +- |
17 |
pym/portage/package/ebuild/prepare_build_dirs.py | 13 +++++++++++++ |
18 |
5 files changed, 22 insertions(+), 8 deletions(-) |
19 |
|
20 |
// CHANGED IN v2: |
21 |
// - fixed FILESDIR to be created before unpack, not after |
22 |
// - removed dupe logic |
23 |
|
24 |
diff --git a/man/ebuild.5 b/man/ebuild.5 |
25 |
index 72b8b6905..e4c866cd2 100644 |
26 |
--- a/man/ebuild.5 |
27 |
+++ b/man/ebuild.5 |
28 |
@@ -411,9 +411,9 @@ not be defined. It is autogenerated from the \fBSRC_URI\fR variable. |
29 |
.B WORKDIR\fR = \fI"${PORTAGE_TMPDIR}/portage/${CATEGORY}/${PF}/work" |
30 |
Contains the path to the package build root. Do not modify this variable. |
31 |
.TP |
32 |
-.B FILESDIR\fR = \fI"${repository_location}/${CATEGORY}/${PN}/files" |
33 |
-Contains the path to the 'files' subdirectory in the package specific |
34 |
-location in given repository. Do not modify this variable. |
35 |
+.B FILESDIR\fR = \fI"${PORTAGE_TMPDIR}/${CATEGORY}/${PF}/files" |
36 |
+Contains the path to the directory in which package-specific auxiliary |
37 |
+files are located. Do not modify this variable. |
38 |
.TP |
39 |
.B EBUILD_PHASE |
40 |
Contains the abreviated name of the phase function that is |
41 |
diff --git a/pym/_emerge/EbuildPhase.py b/pym/_emerge/EbuildPhase.py |
42 |
index fc185fcfd..4b5cbf8fa 100644 |
43 |
--- a/pym/_emerge/EbuildPhase.py |
44 |
+++ b/pym/_emerge/EbuildPhase.py |
45 |
@@ -11,7 +11,8 @@ from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor |
46 |
from _emerge.MiscFunctionsProcess import MiscFunctionsProcess |
47 |
from _emerge.EbuildProcess import EbuildProcess |
48 |
from _emerge.CompositeTask import CompositeTask |
49 |
-from portage.package.ebuild.prepare_build_dirs import _prepare_workdir |
50 |
+from portage.package.ebuild.prepare_build_dirs import (_prepare_workdir, |
51 |
+ _prepare_fake_filesdir) |
52 |
from portage.util import writemsg |
53 |
|
54 |
try: |
55 |
@@ -129,6 +130,9 @@ class EbuildPhase(CompositeTask): |
56 |
# If the environment.bz2 doesn't exist, then ebuild.sh will |
57 |
# source the ebuild as a fallback. |
58 |
|
59 |
+ if self.phase == "unpack": |
60 |
+ _prepare_fake_filesdir(self.settings) |
61 |
+ |
62 |
self._start_lock() |
63 |
|
64 |
def _env_extractor_exit(self, env_extractor): |
65 |
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py |
66 |
index ef29afeab..f8043dbf5 100644 |
67 |
--- a/pym/portage/package/ebuild/config.py |
68 |
+++ b/pym/portage/package/ebuild/config.py |
69 |
@@ -2784,9 +2784,6 @@ class config(object): |
70 |
mydict.pop("EPREFIX", None) |
71 |
mydict.pop("EROOT", None) |
72 |
|
73 |
- if phase == 'depend': |
74 |
- mydict.pop('FILESDIR', None) |
75 |
- |
76 |
if phase not in ("pretend", "setup", "preinst", "postinst") or \ |
77 |
not eapi_exports_replace_vars(eapi): |
78 |
mydict.pop("REPLACING_VERSIONS", None) |
79 |
diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py |
80 |
index 4baae17b1..e7db54bcf 100644 |
81 |
--- a/pym/portage/package/ebuild/doebuild.py |
82 |
+++ b/pym/portage/package/ebuild/doebuild.py |
83 |
@@ -337,7 +337,6 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None, |
84 |
mysettings["EBUILD"] = ebuild_path |
85 |
mysettings["O"] = pkg_dir |
86 |
mysettings.configdict["pkg"]["CATEGORY"] = cat |
87 |
- mysettings["FILESDIR"] = pkg_dir+"/files" |
88 |
mysettings["PF"] = mypv |
89 |
|
90 |
if hasattr(mydbapi, 'repositories'): |
91 |
@@ -390,6 +389,7 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None, |
92 |
mysettings["WORKDIR"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "work") |
93 |
mysettings["D"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image") + os.sep |
94 |
mysettings["T"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "temp") |
95 |
+ mysettings["FILESDIR"] = os.path.join(settings["PORTAGE_BUILDDIR"], "files") |
96 |
|
97 |
# Prefix forward compatability |
98 |
eprefix_lstrip = mysettings["EPREFIX"].lstrip(os.sep) |
99 |
diff --git a/pym/portage/package/ebuild/prepare_build_dirs.py b/pym/portage/package/ebuild/prepare_build_dirs.py |
100 |
index 7e5249b66..e3ae318bd 100644 |
101 |
--- a/pym/portage/package/ebuild/prepare_build_dirs.py |
102 |
+++ b/pym/portage/package/ebuild/prepare_build_dirs.py |
103 |
@@ -396,3 +396,16 @@ def _ensure_log_subdirs(logdir, subdir): |
104 |
while subdir_split: |
105 |
current = os.path.join(current, subdir_split.pop()) |
106 |
ensure_dirs(current, uid=uid, gid=gid, mode=grp_mode, mask=0) |
107 |
+ |
108 |
+def _prepare_fake_filesdir(settings): |
109 |
+ real_filesdir = settings["O"]+"/files" |
110 |
+ symlink_path = settings["FILESDIR"] |
111 |
+ |
112 |
+ try: |
113 |
+ link_target = os.readlink(symlink_path) |
114 |
+ except OSError: |
115 |
+ os.symlink(real_filesdir, symlink_path) |
116 |
+ else: |
117 |
+ if link_target != real_filesdir: |
118 |
+ os.unlink(symlink_path) |
119 |
+ os.symlink(real_filesdir, symlink_path) |
120 |
-- |
121 |
2.12.0 |