Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH v3] install-qa-check: New QA check/cleanup for empty directories
Date: Tue, 30 Jan 2018 07:23:42
Message-Id: 20180130072326.6631-1-mgorny@gentoo.org
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 bin/install-qa-check.d/95empty-dirs | 42 +++++++++++++++++++++++++++++++++++++
18 man/make.conf.5 | 4 ++++
19 pym/portage/const.py | 1 +
20 3 files changed, 47 insertions(+)
21 create mode 100644 bin/install-qa-check.d/95empty-dirs
22
23 diff --git a/bin/install-qa-check.d/95empty-dirs b/bin/install-qa-check.d/95empty-dirs
24 new file mode 100644
25 index 000000000..0d06b278d
26 --- /dev/null
27 +++ b/bin/install-qa-check.d/95empty-dirs
28 @@ -0,0 +1,42 @@
29 +# Warn about and/or remove empty directories installed by ebuild.
30 +
31 +# Rationale: PMS prohibits ebuilds from installing empty directories.
32 +# Cleaning them up from the installation image provides an easy way
33 +# to make sure that ebuilds are not relying on it while making it easy
34 +# for users to override this if they need to.
35 +#
36 +# The ebuilds that need to preserve empty directories should use keepdir
37 +# as documented e.g.:
38 +# https://devmanual.gentoo.org/function-reference/install-functions/index.html
39 +#
40 +# For now, we emit QA warnings for empty directories in /var.
41 +# Additionally, if FEATURES=strict-keepdir is enabled we explicitly
42 +# remove *all* empty directories to trigger breakage.
43 +
44 +find_empty_dirs() {
45 + local warn_dirs=()
46 + local d striparg=
47 +
48 + [[ ${FEATURES} == *strict-keepdir* ]] && striparg=-delete
49 +
50 + while IFS= read -r -d $'\0' d; do
51 + [[ ${d} == ${ED%/}/var/* ]] && warn_dirs+=( "${d}" )
52 + done < <(find "${ED}" -depth -mindepth 1 -type d -empty -print0 ${striparg} | sort -z)
53 +
54 + if [[ ${warn_dirs[@]} ]]; then
55 + eqawarn "One or more empty directories installed to /var:"
56 + eqawarn
57 + for d in "${warn_dirs[@]}"; do
58 + eqawarn " ${d#${ED%/}}"
59 + done
60 + eqawarn
61 + eqawarn "If those directories need to be preserved, please make sure to create"
62 + eqawarn "or mark them for keeping using 'keepdir'. Future versions of Portage"
63 + eqawarn "will strip empty directories from installation image."
64 + fi
65 +}
66 +
67 +find_empty_dirs
68 +: # guarantee successful exit
69 +
70 +# vim:ft=sh
71 diff --git a/man/make.conf.5 b/man/make.conf.5
72 index a81b497bd..cb0f00237 100644
73 --- a/man/make.conf.5
74 +++ b/man/make.conf.5
75 @@ -623,6 +623,10 @@ see \fBinstallsources\fR.
76 Have portage react strongly to conditions that have the potential to be
77 dangerous (like missing or incorrect digests for ebuilds).
78 .TP
79 +.B strict-keepdir
80 +Have portage strictly require keepdir calls in ebuilds. Empty
81 +directories installed without explicit keepdir will be removed.
82 +.TP
83 .B stricter
84 Have portage react strongly to conditions that may conflict with system
85 security provisions (for example textrels, executable stack). Read about
86 diff --git a/pym/portage/const.py b/pym/portage/const.py
87 index e5fa4b67c..655be82b1 100644
88 --- a/pym/portage/const.py
89 +++ b/pym/portage/const.py
90 @@ -184,6 +184,7 @@ SUPPORTED_FEATURES = frozenset([
91 "split-elog",
92 "split-log",
93 "strict",
94 + "strict-keepdir",
95 "stricter",
96 "suidctl",
97 "test",
98 --
99 2.16.1

Replies