51 lines
1.2 KiB
Diff
51 lines
1.2 KiB
Diff
|
commit ceca37901783988204caaf40dff4623d535cc789
|
||
|
Author: Lasse Collin <lasse.collin@tukaani.org>
|
||
|
AuthorDate: Wed Jun 11 20:43:28 2014 +0300
|
||
|
Commit: Lasse Collin <lasse.collin@tukaani.org>
|
||
|
CommitDate: Wed Jun 11 20:43:28 2014 +0300
|
||
|
|
||
|
xzgrep: exit 0 when at least one file matches.
|
||
|
|
||
|
Mimic the original grep behavior and return exit_success when
|
||
|
at least one xz compressed file matches given pattern.
|
||
|
|
||
|
Original bugreport:
|
||
|
https://bugzilla.redhat.com/show_bug.cgi?id=1108085
|
||
|
|
||
|
Thanks to Pavel Raiskup for the patch.
|
||
|
|
||
|
diff --git a/src/scripts/xzgrep.in b/src/scripts/xzgrep.in
|
||
|
index 951266b..018915f 100644
|
||
|
--- a/src/scripts/xzgrep.in
|
||
|
+++ b/src/scripts/xzgrep.in
|
||
|
@@ -147,7 +147,9 @@ if test $# -eq 0; then
|
||
|
fi
|
||
|
|
||
|
exec 3>&1
|
||
|
-res=0
|
||
|
+
|
||
|
+# res=1 means that no file matched yet
|
||
|
+res=1
|
||
|
|
||
|
for i; do
|
||
|
case $i in
|
||
|
@@ -195,8 +197,17 @@ for i; do
|
||
|
fi >&3 5>&-
|
||
|
)
|
||
|
r=$?
|
||
|
+
|
||
|
+ # fail occured previously, nothing worse can happen
|
||
|
+ test $res -gt 1 && continue
|
||
|
+
|
||
|
test "$xz_status" -eq 0 || test "$xz_status" -eq 2 \
|
||
|
|| test "$(kill -l "$xz_status" 2> /dev/null)" = "PIPE" || r=2
|
||
|
- test $res -lt $r && res=$r
|
||
|
+
|
||
|
+ # still no match
|
||
|
+ test $r -eq 1 && continue
|
||
|
+
|
||
|
+ # 0 == match, >=2 == fail
|
||
|
+ res=$r
|
||
|
done
|
||
|
exit $res
|