commit:     57616accfd55b736e3b402ead96637e23792772a
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Thu Nov 19 18:24:44 2020 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Thu Nov 19 18:26:05 2020 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=57616acc

sys-kernel/linux-firmware: check each command in pipeline manually

We cannot use Bash's pipefail option because grep can return exit status 1
to indicate that no line was selected which isn't an error.

Fixes: 9bf0896d9 ("sys-kernel/linux-firmware: use copy-firmware.sh to install 
firmwares")
Closes: https://bugs.gentoo.org/754960
Package-Manager: Portage-3.0.9, Repoman-3.0.2
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 sys-kernel/linux-firmware/linux-firmware-20201022-r2.ebuild | 11 +++++++++--
 sys-kernel/linux-firmware/linux-firmware-99999999.ebuild    | 11 +++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/sys-kernel/linux-firmware/linux-firmware-20201022-r2.ebuild 
b/sys-kernel/linux-firmware/linux-firmware-20201022-r2.ebuild
index bc7bc76e3b0..01b85b27a4f 100644
--- a/sys-kernel/linux-firmware/linux-firmware-20201022-r2.ebuild
+++ b/sys-kernel/linux-firmware/linux-firmware-20201022-r2.ebuild
@@ -276,12 +276,19 @@ src_install() {
                        [[ -s "${files_to_keep}" ]] || die "grep failed, empty 
config file?"
 
                        einfo "Applying USE=savedconfig; Removing all files not 
listed in config ..."
-                       set -o pipefail
                        find ! -type d -printf "%P\n" \
                                | grep -Fvx -f "${files_to_keep}" \
                                | xargs -d '\n' --no-run-if-empty rm -v
 
-                       [[ ${?} -ne 0 ]] && die "Failed to remove files not 
listed in config"
+                       if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
+                               die "Find failed to print installed files"
+                       elif [[ ${PIPESTATUS[1]} -eq 2 ]]; then
+                               # grep returns exit status 1 if no lines were 
selected
+                               # which is the case when we want to keep all 
files
+                               die "Grep failed to select files to keep"
+                       elif [[ ${PIPESTATUS[2]} -ne 0 ]]; then
+                               die "Failed to remove files not listed in 
config"
+                       fi
                fi
        fi
 

diff --git a/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild 
b/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild
index bc7bc76e3b0..01b85b27a4f 100644
--- a/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild
+++ b/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild
@@ -276,12 +276,19 @@ src_install() {
                        [[ -s "${files_to_keep}" ]] || die "grep failed, empty 
config file?"
 
                        einfo "Applying USE=savedconfig; Removing all files not 
listed in config ..."
-                       set -o pipefail
                        find ! -type d -printf "%P\n" \
                                | grep -Fvx -f "${files_to_keep}" \
                                | xargs -d '\n' --no-run-if-empty rm -v
 
-                       [[ ${?} -ne 0 ]] && die "Failed to remove files not 
listed in config"
+                       if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
+                               die "Find failed to print installed files"
+                       elif [[ ${PIPESTATUS[1]} -eq 2 ]]; then
+                               # grep returns exit status 1 if no lines were 
selected
+                               # which is the case when we want to keep all 
files
+                               die "Grep failed to select files to keep"
+                       elif [[ ${PIPESTATUS[2]} -ne 0 ]]; then
+                               die "Failed to remove files not listed in 
config"
+                       fi
                fi
        fi
 

Reply via email to