xzgrep: return 0 when at least one file matches

Resolves: #1109122
Version: 5.1.2-12alpha
This commit is contained in:
Pavel Raiskup 2014-06-13 11:58:34 +02:00
parent 19677d2183
commit d23e30817f
3 changed files with 123 additions and 1 deletions

View File

@ -0,0 +1,60 @@
commit 1e60f2c0a0ee6c18b02943ce56214799a70aac26 (HEAD, origin/master, origin/HEAD, master)
Author: Lasse Collin <lasse.collin@tukaani.org>
AuthorDate: Wed Jun 11 21:03:25 2014 +0300
Commit: Lasse Collin <lasse.collin@tukaani.org>
CommitDate: Wed Jun 11 21:03:25 2014 +0300
xzgrep: Add a test for the previous fix.
This is a simplified version of Pavel Raiskup's
original patch.
diff --git a/tests/test_scripts.sh b/tests/test_scripts.sh
index 293929e..7ac1fea 100755
--- a/tests/test_scripts.sh
+++ b/tests/test_scripts.sh
@@ -12,16 +12,18 @@
# If scripts weren't built, this test is skipped.
XZ=../src/xz/xz
XZDIFF=../src/scripts/xzdiff
-test -x "$XZ" || XZ=
-test -x "$XZDIFF" || XZDIFF=
-if test -z "$XZ" || test -z "$XZDIFF"; then
+XZGREP=../src/scripts/xzgrep
+
+for i in XZ XZDIFF XZGREP; do
+ eval test -x "\$$i" && continue
(exit 77)
exit 77
-fi
+done
PATH=`pwd`/../src/xz:$PATH
export PATH
+test -z "$srcdir" && srcdir=.
preimage=$srcdir/files/good-1-check-crc32.xz
samepostimage=$srcdir/files/good-1-check-crc64.xz
otherpostimage=$srcdir/files/good-1-lzma2-1.xz
@@ -50,5 +52,21 @@ if test "$status" != 2 ; then
exit 1
fi
+# The exit status must be 0 when a match was found at least from one file,
+# and 1 when no match was found in any file.
+for pattern in el Hello NOMATCH; do
+ for opts in "" "-l" "-h" "-H"; do
+ "$XZGREP" $opts $pattern \
+ "$srcdir/files/good-1-lzma2-1.xz" \
+ "$srcdir/files/good-2-lzma2.xz" > /dev/null 2>&1
+ status=$?
+ test $status = 0 && test $pattern != NOMATCH && continue
+ test $status = 1 && test $pattern = NOMATCH && continue
+ echo "wrong exit status from xzgrep"
+ (exit 1)
+ exit 1
+ done
+done
+
(exit 0)
exit 0

View File

@ -0,0 +1,50 @@
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

14
xz.spec
View File

@ -3,7 +3,7 @@
Summary: LZMA compression utilities
Name: xz
Version: 5.1.2
Release: 11alpha%{?dist}
Release: 12alpha%{?dist}
License: LGPLv2+
Group: Applications/File
# official upstream release
@ -29,6 +29,13 @@ Patch1: xz-5.1.2alpha-xzgrep-and-h-option.patch
# ~> #1015924
Patch2: xz-5.1.2alpha-less-version-check.patch
# xzgrep: return 0 when at least one file matches (+ test)
# ~> upstream (ceca37901783)
# ~> #1109122
Patch3: xz-5.1.2alpha-xzgrep-exit.patch
Patch4: xz-5.1.2alpha-xzgrep-exit-test.patch
%description
XZ Utils are an attempt to make LZMA compression easy to use on free (as in
freedom) operating systems. This is achieved by providing tools and libraries
@ -93,6 +100,8 @@ commands that deal with the older LZMA format.
%patch0 -p1 -b .man-page-day
%patch1 -p1 -b .xzgrep-and-h-option
%patch2 -p1 -b .less-version-check
%patch3 -p1 -b .xzgrep-exit-status
%patch4 -p1 -b .xzgrep-exit-status-test
for i in `find . -name config.sub`; do
perl -pi -e "s/ppc64-\*/ppc64-\* \| ppc64p7-\*/" $i
@ -174,6 +183,9 @@ rm -rf %{buildroot}
%{_mandir}/man1/*lz*
%changelog
* Fri Jun 13 2014 Pavel Raiskup <praiskup@redhat.com> - 5.1.2-12alpha
- xzgrep: return 0 when at least one file matches (#1109122)
* Sun Jun 08 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 5.1.2-11alpha
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild