From: Luke Shumaker <>

`grep -q` may exit as soon as it finds a match; this is a good optimization
for when the input is a file.  However, if the input is the output of
another program, then that other program will receive SIGPIPE, and further
writes will fail.  When this happens, it might (bsdtar does) print a
message about a "write error" to stderr.  Which is going to confuse and
alarm the user.

In one of the cases, this had already been mitigated by wrapping
bsdtar in "echo "$(bsdtar ...)", as Bash builtin echo doesn't complain
if it gets SIGPIPE.  However, that means we're storing the entire
output of bsdtar in memory, which is silly.
 db-functions         | 2 +-
 test/lib/common.bash | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/db-functions b/db-functions
index 58b753a..ee390ff 100644
--- a/db-functions
+++ b/db-functions
@@ -303,7 +303,7 @@ check_pkgfile() {
        in_array "${pkgarch}" "${ARCHES[@]}" 'any' || return 1
-       if echo "${pkgfile##*/}" | grep -q "^${pkgname}-${pkgver}-${pkgarch}"; 
+       if echo "${pkgfile##*/}" | grep "^${pkgname}-${pkgver}-${pkgarch}" 
&>/dev/null; then
                return 0
                return 1
diff --git a/test/lib/common.bash b/test/lib/common.bash
index 45e4800..ab805dd 100644
--- a/test/lib/common.bash
+++ b/test/lib/common.bash
@@ -215,7 +215,7 @@ checkPackageDB() {
                                for db in ${DBEXT} ${FILESEXT}; do
                                        [ -r 
"${FTP_BASE}/${repo}/os/${repoarch}/${repo}${db%.tar.*}" ]
-                                       bsdtar -xf 
"${FTP_BASE}/${repo}/os/${repoarch}/${repo}${db%.tar.*}" -O | grep -q 
+                                       bsdtar -xf 
"${FTP_BASE}/${repo}/os/${repoarch}/${repo}${db%.tar.*}" -O | grep 
"${pkgfile%${PKGEXT}}" &>/dev/null
@@ -269,7 +269,7 @@ checkRemovedPackageDB() {
                for tarch in ${tarches[@]}; do
                        if [ -r 
"${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" ]; then
                                for pkgname in ${pkgnames[@]}; do
-                                       echo "$(bsdtar -xf 
"${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" -O)" | grep -qv ${pkgname}
+                                       bsdtar -xf 
"${FTP_BASE}/${repo}/os/${tarch}/${repo}${db%.tar.*}" -O | grep -v ${pkgname} 

Reply via email to