The QA_INSTALL_PATHS variable exempts paths from "unexpected paths"
warnings generated by metadata/install-qa-check.d/08gentoo-paths.
If the QA_STRICT_INSTALL_PATHS variable is set then any exemptions
in QA_INSTALL_PATHS are ignored.

Since we probably don't want to whitelist /nix for all ebuilds,
this patch will allow us to whitelist it with a setting like this
in global scope of the nix ebuilds:

QA_INSTALL_PATHS=( /nix )

Bug: https://bugs.gentoo.org/670902
Signed-off-by: Zac Medico <zmed...@gentoo.org>
---
 metadata/install-qa-check.d/08gentoo-paths | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/metadata/install-qa-check.d/08gentoo-paths 
b/metadata/install-qa-check.d/08gentoo-paths
index 3ee887df08f..a3289b112dd 100644
--- a/metadata/install-qa-check.d/08gentoo-paths
+++ b/metadata/install-qa-check.d/08gentoo-paths
@@ -60,6 +60,27 @@ gentoo_path_check() {
 
        ${shopt_save}
 
+       if [[ ${#bad_paths[@]} -gt 0 && ${QA_INSTALL_PATHS} &&
+               ${QA_STRICT_INSTALL_PATHS-unset} == unset ]]; then
+               local filtered_paths=()
+               local grep_args=()
+               local qa_install_paths
+               if [[ $(declare -p QA_INSTALL_PATHS) == "declare -a "* ]]; then
+                       qa_install_paths=( "${QA_INSTALL_PATHS[@]}" )
+               else
+                       set -f
+                       qa_install_paths=( ${QA_INSTALL_PATHS} )
+                       set +f
+               fi
+               for x in "${qa_install_paths[@]}"; do
+                       grep_args+=( -e "^/${x#/}\$" )
+               done
+               while read -r -d ''; do
+                       [[ ${REPLY} ]] && filtered_paths+=( "${REPLY}" )
+               done < <(printf -- '%s\0' "${bad_paths[@]}" | grep -zv 
"${grep_args[@]}")
+               bad_paths=( "${filtered_paths[@]}" )
+       fi
+
        # report
        # ------
        if [[ -n ${bad_paths[@]} ]]; then
-- 
2.18.1


Reply via email to