Gentoo Archives: gentoo-portage-dev

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