1 |
On 01/28/2018 01:50 AM, Michał Górny wrote: |
2 |
> Warn about empty directories installed to /var in install-qa-check phase |
3 |
> (that were not "filled" using keepdir), to help developers stop relying |
4 |
> upon Portage preserving them. Those directories are rather unlikely to |
5 |
> be false positives. |
6 |
> |
7 |
> Furthermore, remove all the empty directories if FEATURES=strict-keepdir |
8 |
> is used to catch even more problems (intended for developers). Here |
9 |
> warnings are not really suitable since there will be a high number |
10 |
> of false positives. |
11 |
> |
12 |
> The PMS specifies the behavior upon merging empty directories |
13 |
> as undefined, and specifically prohibits ebuilds from attempting |
14 |
> to install empty directories. However, ebuilds occasionally still fall |
15 |
> into the trap of relying on 'dodir' preserving the directory. Make |
16 |
> the Portage behavior more strict in order to prevent that. |
17 |
> --- |
18 |
> bin/install-qa-check.d/95empty-dirs | 43 +++++++++++++++++++++++++++++++++++++ |
19 |
> 1 file changed, 43 insertions(+) |
20 |
> create mode 100644 bin/install-qa-check.d/95empty-dirs |
21 |
> |
22 |
> diff --git a/bin/install-qa-check.d/95empty-dirs b/bin/install-qa-check.d/95empty-dirs |
23 |
> new file mode 100644 |
24 |
> index 000000000..a9cda7fe1 |
25 |
> --- /dev/null |
26 |
> +++ b/bin/install-qa-check.d/95empty-dirs |
27 |
> @@ -0,0 +1,43 @@ |
28 |
> +# Warn about and/or remove empty directories installed by ebuild. |
29 |
> + |
30 |
> +# Rationale: PMS prohibits ebuilds from installing empty directories. |
31 |
> +# Cleaning them up from the installation image provides an easy way |
32 |
> +# to make sure that ebuilds are not relying on it while making it easy |
33 |
> +# for users to override this if they need to. |
34 |
> +# |
35 |
> +# The ebuilds that need to preserve empty directories should use keepdir |
36 |
> +# as documented e.g.: |
37 |
> +# https://devmanual.gentoo.org/function-reference/install-functions/index.html |
38 |
> +# |
39 |
> +# For now, we emit QA warnings for empty directories in /var. |
40 |
> +# Additionally, if FEATURES=strict-keepdir is enabled we explicitly |
41 |
> +# remove *all* empty directories to trigger breakage. |
42 |
> + |
43 |
> +find_empty_dirs() { |
44 |
> + local warn_dirs=() |
45 |
> + local d strip= |
46 |
> + |
47 |
> + [[ ${FEATURES} == *strict-keepdir* ]] && strip=1 |
48 |
|
49 |
strict-keepdir has to be added to portage.const.SUPPORTED_FEATURES. |
50 |
Maybe also document it in man/make.conf.5? |
51 |
|
52 |
> + |
53 |
> + while IFS= read -r -d $'\0' d; do |
54 |
> + warn_dirs+=( "${d}" ) |
55 |
> + done < <(find "${ED}" -mindepth 1 -type d -empty -print0) |
56 |
> + |
57 |
> + if [[ ${warn_dirs[@]} ]]; then |
58 |
> + eqawarn "One or more empty directories installed to /var:" |
59 |
> + eqawarn |
60 |
> + for d in "${warn_dirs[@]}"; do |
61 |
> + eqawarn " ${d#${ED%/}}" |
62 |
> + [[ ${strip} ]] && rmdir "${d}" |
63 |
Do you also want the strip logic to traverse upwards, removing |
64 |
directories that contain only empty directories? |
65 |
|
66 |
> + done |
67 |
> + eqawarn |
68 |
> + eqawarn "If those directories need to be preserved, please make sure to create" |
69 |
> + eqawarn "or mark them for keeping using 'keepdir'. Future versions of Portage" |
70 |
> + eqawarn "will strip empty directories from installation image." |
71 |
> + fi |
72 |
> +} |
73 |
> + |
74 |
> +find_empty_dirs |
75 |
> +: # guarantee successful exit |
76 |
> + |
77 |
> +# vim:ft=sh |
78 |
> |
79 |
|
80 |
|
81 |
-- |
82 |
Thanks, |
83 |
Zac |