1 |
Warn about empty directories installed to /var in install-qa-check phase |
2 |
(that were not "filled" using keepdir), to help developers stop relying |
3 |
upon Portage preserving them. Those directories are rather unlikely to |
4 |
be false positives. |
5 |
|
6 |
Furthermore, remove all the empty directories if FEATURES=strict-keepdir |
7 |
is used to catch even more problems (intended for developers). Here |
8 |
warnings are not really suitable since there will be a high number |
9 |
of false positives. |
10 |
|
11 |
The PMS specifies the behavior upon merging empty directories |
12 |
as undefined, and specifically prohibits ebuilds from attempting |
13 |
to install empty directories. However, ebuilds occasionally still fall |
14 |
into the trap of relying on 'dodir' preserving the directory. Make |
15 |
the Portage behavior more strict in order to prevent that. |
16 |
|
17 |
[v4: now with LC_COLLATE=C for sorting] |
18 |
--- |
19 |
bin/install-qa-check.d/95empty-dirs | 42 +++++++++++++++++++++++++++++++++++++ |
20 |
man/make.conf.5 | 4 ++++ |
21 |
pym/portage/const.py | 1 + |
22 |
3 files changed, 47 insertions(+) |
23 |
create mode 100644 bin/install-qa-check.d/95empty-dirs |
24 |
|
25 |
diff --git a/bin/install-qa-check.d/95empty-dirs b/bin/install-qa-check.d/95empty-dirs |
26 |
new file mode 100644 |
27 |
index 000000000..8599db395 |
28 |
--- /dev/null |
29 |
+++ b/bin/install-qa-check.d/95empty-dirs |
30 |
@@ -0,0 +1,42 @@ |
31 |
+# Warn about and/or remove empty directories installed by ebuild. |
32 |
+ |
33 |
+# Rationale: PMS prohibits ebuilds from installing empty directories. |
34 |
+# Cleaning them up from the installation image provides an easy way |
35 |
+# to make sure that ebuilds are not relying on it while making it easy |
36 |
+# for users to override this if they need to. |
37 |
+# |
38 |
+# The ebuilds that need to preserve empty directories should use keepdir |
39 |
+# as documented e.g.: |
40 |
+# https://devmanual.gentoo.org/function-reference/install-functions/index.html |
41 |
+# |
42 |
+# For now, we emit QA warnings for empty directories in /var. |
43 |
+# Additionally, if FEATURES=strict-keepdir is enabled we explicitly |
44 |
+# remove *all* empty directories to trigger breakage. |
45 |
+ |
46 |
+find_empty_dirs() { |
47 |
+ local warn_dirs=() |
48 |
+ local d striparg= |
49 |
+ |
50 |
+ [[ ${FEATURES} == *strict-keepdir* ]] && striparg=-delete |
51 |
+ |
52 |
+ while IFS= read -r -d $'\0' d; do |
53 |
+ [[ ${d} == ${ED%/}/var/* ]] && warn_dirs+=( "${d}" ) |
54 |
+ done < <(find "${ED}" -depth -mindepth 1 -type d -empty -print0 ${striparg} | LC_COLLATE=C sort -z) |
55 |
+ |
56 |
+ if [[ ${warn_dirs[@]} ]]; then |
57 |
+ eqawarn "One or more empty directories installed to /var:" |
58 |
+ eqawarn |
59 |
+ for d in "${warn_dirs[@]}"; do |
60 |
+ eqawarn " ${d#${ED%/}}" |
61 |
+ done |
62 |
+ eqawarn |
63 |
+ eqawarn "If those directories need to be preserved, please make sure to create" |
64 |
+ eqawarn "or mark them for keeping using 'keepdir'. Future versions of Portage" |
65 |
+ eqawarn "will strip empty directories from installation image." |
66 |
+ fi |
67 |
+} |
68 |
+ |
69 |
+find_empty_dirs |
70 |
+: # guarantee successful exit |
71 |
+ |
72 |
+# vim:ft=sh |
73 |
diff --git a/man/make.conf.5 b/man/make.conf.5 |
74 |
index a81b497bd..cb0f00237 100644 |
75 |
--- a/man/make.conf.5 |
76 |
+++ b/man/make.conf.5 |
77 |
@@ -623,6 +623,10 @@ see \fBinstallsources\fR. |
78 |
Have portage react strongly to conditions that have the potential to be |
79 |
dangerous (like missing or incorrect digests for ebuilds). |
80 |
.TP |
81 |
+.B strict-keepdir |
82 |
+Have portage strictly require keepdir calls in ebuilds. Empty |
83 |
+directories installed without explicit keepdir will be removed. |
84 |
+.TP |
85 |
.B stricter |
86 |
Have portage react strongly to conditions that may conflict with system |
87 |
security provisions (for example textrels, executable stack). Read about |
88 |
diff --git a/pym/portage/const.py b/pym/portage/const.py |
89 |
index e5fa4b67c..655be82b1 100644 |
90 |
--- a/pym/portage/const.py |
91 |
+++ b/pym/portage/const.py |
92 |
@@ -184,6 +184,7 @@ SUPPORTED_FEATURES = frozenset([ |
93 |
"split-elog", |
94 |
"split-log", |
95 |
"strict", |
96 |
+ "strict-keepdir", |
97 |
"stricter", |
98 |
"suidctl", |
99 |
"test", |
100 |
-- |
101 |
2.16.1 |