diff --git a/SOURCES/xz-5.1.2alpha-xzgrep-exit-test.patch b/SOURCES/xz-5.1.2alpha-xzgrep-exit-test.patch new file mode 100644 index 0000000..352aa2d --- /dev/null +++ b/SOURCES/xz-5.1.2alpha-xzgrep-exit-test.patch @@ -0,0 +1,60 @@ +commit 1e60f2c0a0ee6c18b02943ce56214799a70aac26 (HEAD, origin/master, origin/HEAD, master) +Author: Lasse Collin +AuthorDate: Wed Jun 11 21:03:25 2014 +0300 +Commit: Lasse Collin +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 diff --git a/SOURCES/xz-5.1.2alpha-xzgrep-exit.patch b/SOURCES/xz-5.1.2alpha-xzgrep-exit.patch new file mode 100644 index 0000000..a64b464 --- /dev/null +++ b/SOURCES/xz-5.1.2alpha-xzgrep-exit.patch @@ -0,0 +1,50 @@ +commit ceca37901783988204caaf40dff4623d535cc789 +Author: Lasse Collin +AuthorDate: Wed Jun 11 20:43:28 2014 +0300 +Commit: Lasse Collin +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 diff --git a/SPECS/xz.spec b/SPECS/xz.spec index f4cb1b7..13413fd 100644 --- a/SPECS/xz.spec +++ b/SPECS/xz.spec @@ -3,7 +3,7 @@ Summary: LZMA compression utilities Name: xz Version: 5.1.2 -Release: 9alpha%{?dist} +Release: 12alpha%{?dist} License: LGPLv2+ Group: Applications/File # official upstream release @@ -29,6 +29,12 @@ Patch1: xz-5.1.2alpha-xzgrep-and-h-option.patch # ~> #1082639, #1015924 Patch2: xz-5.1.2alpha-less-version-check.patch +# fix for bad xzgrep exit value when not _all_ files match +# ~> upstream (ceca37901783) +# ~> #1109123 +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 @@ -84,6 +90,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 @@ -161,6 +169,9 @@ rm -rf %{buildroot} %{_mandir}/man1/*lz* %changelog +* Wed Jul 08 2015 Pavel Raiskup - 5.1.2-12alpha +- xzgrep: return 0 when at least one file matches (rhbz#1109123) + * Tue Jun 17 2014 Pavel Raiskup - 5.1.2-9alpha - better check the version of less binary (#1082639)