[arch-projects] [dbscripts] [PATCH v2 2/2] fix potential bsdtar stream close error by grep

Eli Schwartz eschwartz at archlinux.org
Sun Sep 9 16:33:55 UTC 2018


From: anthraxx <anthraxx at archlinux.org>

This silences a useless error message that confuses the user.

bsdtar doesn't like it when the stream gets closed before it finishes
which may be the case when grep found its match on potentially huge
archives. Instead of suppressing the whole stderr , we find all matches
with grep, then use a second pass with `tail` to find only the last
match, which ensures the stream remains open for bsdtar but we may still
catch and see useful messages on stderr.

This works because tail has the useful property of not closing early.

Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
---
 db-functions | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/db-functions b/db-functions
index 0491c22d..6d6084a9 100644
--- a/db-functions
+++ b/db-functions
@@ -174,7 +174,7 @@ repo_unlock () { #repo_unlock <repo-name> <arch>
 _grep_pkginfo() {
 	local _ret
 
-	_ret="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | grep -m 1 "^${2} = ")"
+	_ret="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | grep "^${2} = " | tail -1)"
 	echo "${_ret#${2} = }"
 }
 
@@ -182,7 +182,7 @@ _grep_pkginfo() {
 _grep_buildinfo() {
 	local _ret
 
-	_ret="$(/usr/bin/bsdtar -xOqf "$1" .BUILDINFO | grep -m 1 "^${2} = ")"
+	_ret="$(/usr/bin/bsdtar -xOqf "$1" .BUILDINFO | grep "^${2} = " | tail -1)"
 	echo "${_ret#${2} = }"
 }
 
-- 
2.18.0


More information about the arch-projects mailing list