[dbscripts,v2,2/2] fix potential bsdtar stream close error by grep

Message ID 20180909163355.31125-1-eschwartz@archlinux.org
State New
Headers show
Series
  • Untitled series #139
Related show

Commit Message

Eli Schwartz via arch-projects Sept. 9, 2018, 4:33 p.m. UTC
From: anthraxx <anthraxx@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@archlinux.org>
---
 db-functions | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch

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} = }"
 }