* lib/missing: If the default `tar' program fails with the given arguments, and GNU tar is not available, don't try to re-run the default `tar' with a munged command line (e.g., ditching possibly unportable options), as that could be subtly alter the intended semantics (and maybe even create a somewhat corrupted tarball). Also, it's worth noting that the main purpose of the `missing' script is to allow a non-developer to build the package in the face of slightly-skewed timestamps, not to provide wrappers for all the maintainer tools -- so we don't have to try too hard when `missing' is just called to wrap `tar'. * tests/missing-tar.test: New test. * tests/Makefile.am (TESTS): Add it. --- ChangeLog | 16 +++++ lib/missing | 18 +----- tests/Makefile.am | 1 + tests/Makefile.in | 1 + tests/missing-tar.test | 153 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 17 deletions(-) create mode 100755 tests/missing-tar.test
diff --git a/ChangeLog b/ChangeLog index 06f3abd..164d9bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2011-10-30 Stefano Lattarini <stefano.lattar...@gmail.com> + missing: don't try to re-run tar with a munged command line + * lib/missing: If the default `tar' program fails with the given + arguments, and GNU tar is not available, don't try to re-run the + default `tar' with a munged command line (e.g., ditching possibly + unportable options), as that could be subtly alter the intended + semantics (and maybe even create a somewhat corrupted tarball). + Also, it's worth noting that the main purpose of the `missing' + script is to allow a non-developer to build the package in the + face of slightly-skewed timestamps, not to provide wrappers for + all the maintainer tools -- so we don't have to try too hard + when `missing' is just called to wrap `tar'. + * tests/missing-tar.test: New test. + * tests/Makefile.am (TESTS): Add it. + +2011-10-30 Stefano Lattarini <stefano.lattar...@gmail.com> + missing: inform the user if GNU tar is called * lib/missing: If the code trying to run GNU tar is reached, it means that the previous attempt to run the default tar program diff --git a/lib/missing b/lib/missing index 34c3239..7f4950e 100755 --- a/lib/missing +++ b/lib/missing @@ -1,7 +1,7 @@ #! /bin/sh # Common stub for a few missing GNU programs while installing. -scriptversion=2011-10-30.08; # UTC +scriptversion=2011-10-30.10; # UTC # Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006, # 2008, 2009, 2010, 2011 Free Software Foundation, Inc. @@ -329,22 +329,6 @@ WARNING: I can't seem to be able to run \`tar' with the given arguments. Trying to use GNU tar (\"$cmd\") instead ..." exec $cmd "$@" done - firstarg=$1 - if shift; then - case $firstarg in - *o*) - firstarg=`echo "$firstarg" | sed s/o//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - case $firstarg in - *h*) - firstarg=`echo "$firstarg" | sed s/h//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - fi - echo 1>&2 "\ WARNING: I can't seem to be able to run \`tar' with the given arguments. You may want to install GNU tar or Free paxutils, or check the diff --git a/tests/Makefile.am b/tests/Makefile.am index 301a2b9..7bc18b4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -574,6 +574,7 @@ missing3.test \ missing4.test \ missing5.test \ missing6.test \ +missing-tar.test \ mkinstall.test \ mkinst2.test \ mkinst3.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 0eece13..742e7ef 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -858,6 +858,7 @@ missing3.test \ missing4.test \ missing5.test \ missing6.test \ +missing-tar.test \ mkinstall.test \ mkinst2.test \ mkinst3.test \ diff --git a/tests/missing-tar.test b/tests/missing-tar.test new file mode 100755 index 0000000..e90e03a --- /dev/null +++ b/tests/missing-tar.test @@ -0,0 +1,153 @@ +#! /bin/sh +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test how the `missing' script wraps the`tar' program . +# FIXME: we should also try to run the `missing' script with the +# $CONFIG_SHELL ... + +. ./defs || Exit 1 + +set -e + +# FIXME: make this working with "installcheck" too ... +cp "$testsrcdir"/../lib/missing . \ + || fatal_ "failed to fetch auxiliary script \`missing'" + +old_PATH=$PATH; export old_PATH +new_PATH=`pwd`/bin$PATH_SEPARATOR$PATH +mkdir bin + +cat > data.txt <<'END' +To be, or not to be: that is the question: +Whether 'tis nobler in the mind to suffer +... +END + +cat > nonesuch <<'END' +#!/bin/sh +exit 127 +END +chmod a+x nonesuch + +# Simple runs. +for nullify_gnu in yes no; do + case $nullify_gnu in + yes) + cp nonesuch bin/gtar + cp nonesuch bin/gnutar + PATH=$new_PATH; export PATH; + mkdir simple-nognu + cd simple-nognu + ;; + no) + mkdir simple-dflt + cd simple-dflt + ;; + *) + Exit 99 # Can't happen. + ;; + esac + cp ../data.txt foobar.txt + ../missing --run tar cvf mu.tar foobar.txt + rm -f foobar.txt + test -f mu.tar + ../missing --run tar tf mu.tar >output 2>&1 || { cat output; Exit 1; } + cat output + $FGREP 'foobar.txt' output + test ! -f foobar.txt + ../missing --run tar xvf mu.tar + diff ../data.txt foobar.txt + PATH=$old_PATH; export PATH; + cd .. +done + +rm -f bin/* + +# Helper scripts and functions for next tests. + +cat > fake-gnu-tar <<'END' +#!/bin/sh +case " $* " in *\ --version\ *) echo fake GNU tar; exit $?;; esac +PATH=$old_PATH; export PATH +exec tar "$@" +END +chmod a+x fake-gnu-tar + +cat > failing-tar <<'END' +#!/bin/sh +echo "Error message from tar passed through" >&2 +exit 1 +END +chmod a+x failing-tar + +grep_tar_failed () +{ + grep "WARNING:.* can't.* run \`tar' with .*given arguments" $* +} + +# The `tar' program does not work with the given options, but we have +# gtar or gnutar. +cp failing-tar bin/tar +for pfx in g gnu; do + case $pfx in g) othpfx=gnu;; gnu) othpfx=g;; *) Exit 99;; esac + cp nonesuch bin/${othpfx}tar + if ${pfx}tar --version | grep GNU; then :; else + cp fake-gnu-tar bin/${pfx}tar + fi + tarball=foo-$pfx.tar + PATH=$new_PATH; export PATH + ./missing --run tar cvf $tarball ./data.txt 2>stderr \ + || { cat stderr >&2; Exit 1; } + cat stderr >&2 + PATH=$old_PATH; export PATH + test -f $tarball + grep_tar_failed stderr + grep "Error message from tar passed through" stderr + grep "[Tt]rying to use GNU tar.*${pfx}tar" stderr + grep "${othpfx}tar" stderr && Exit 1 + : # For shells with broken 'set -e' +done + +rm -f bin/* + +# The `tar' program does not work with the given options, and we don't +# have neither gtar nor gnutar. +cp failing-tar bin/tar +cp nonesuch bin/gtar +cp nonesuch bin/gnutar +PATH=$new_PATH; export PATH +./missing --run tar cvf foo.tar ./data.txt 2>stderr \ + && { cat stderr >&2; Exit 1; } +cat stderr >&2 +PATH=$old_PATH; export PATH +test ! -f foo.tar +grep_tar_failed stderr +grep "Error message from tar passed through" stderr +grep "[iI]nstall GNU tar or Free [pP]axutils" stderr +$EGREP "(g|gnu)tar" stderr && Exit 1 + +rm -f bin/* + +# We try to use an option that causes any `tar' program (GNU or non-GNU) to. +sh -x ./missing --run tar --bad-unknonw-option cvf foo.tar ./data.txt 2>stderr \ + && { cat stderr >&2; Exit 1; } +cat stderr >&2 +test ! -f foo.tar +grep_tar_failed stderr +grep "bad-unknonw-option" stderr +test `$EGREP -c "[Tt]rying to use GNU tar.*(g|gnu)tar" stderr` -eq 1 + +: -- 1.7.2.3