help-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-tar] Trouble with tar -xzf when using --files-from=-


From: Tony Olekshy
Subject: [Help-tar] Trouble with tar -xzf when using --files-from=-
Date: Tue, 20 Oct 2015 19:20:22 -0600
User-agent: KMail/4.10.5 (Linux/3.11.10-100.fc18.x86_64; KDE/4.10.5; x86_64; ; )

Hello.

I'm having trouble understanding why I can't pipe the output of a
tar -tzf a.tgz ... through to a tar -xzf a.tgz --files=from=- ...
without producing what appear to be spurious messages. In practice
I want to place a filter in that pipeline to select just what to
extract, but the following script simplifies that out to just show
the problem I'm encountering.

Here are my test script and my questions thereto. Any insight you
can provide me with would be appreciated.

#!/bin/bash
#-----------------------------------------------------------------------
#
#   Subject: Trouble with tar -xzf when using --files-from=-
#
#   From Tony Olekshy, Avra Software Lab Inc., 2015-10-20.
#
#   The following has been reproduced with the GNU tar 1.26 that came
#   with Fedora release 18, with GNU tar 1.27.1 and 1.28 which I just
#   compiled on Fedora release 18, and with the GNU tar 1.23 that came
#   with Red Hat Enterprise Linux Server release 6.6.
#
#   Step 5 below produces these messages:
#
#       tar: ./foo: Not found in archive
#       tar: ./foo/bar: Not found in archive
#       tar: Exiting with failure status due to previous errors
#
#   But step 6 shows that ./foo & ./foo/bar were in fact correctly
#   extracted into $TEST/into, so they were found in the archive!
#
#   My questions are: Why does step 5 produce those messages?
#   What am I misunderstanding, or is there some bug in tar?
#
set -v #----------------------------------------------------------------

: Step 1: Create the testing environment...
:
export TAR=/bin/tar TEST=~/test

echo; $TAR --version | grep 'GNU tar'

mkdir -p $TEST/from/foo $TEST/into
rm -rf $TEST/archive.tgz $TEST/into/*
date > $TEST/from/foo/bar

: Step 2: Show the contents of $TEST...
:
echo; cd $TEST; find . | sort | xargs ls -ld

: Step 3: Create $TEST/archive.tgz...
:
cd $TEST/from; find .   \
                        \
    | $TAR -vczf $TEST/archive.tgz --files-from=- --no-recursion

: Step 4: Show the contents of archive.tgz...
:
cd $TEST; $TAR -tzf $TEST/archive.tgz

: Step 5: Extract files from archive.tgz using --files-from...
:
cd $TEST; $TAR -tzf $TEST/archive.tgz | ( cd $TEST/into;

    $TAR -vxzf $TEST/archive.tgz --files-from=- --no-recursion )

: Step 6: Show the contents of $TEST...
:
echo; cd $TEST; find . | sort | xargs ls -ld

exit #------------------------------------------------------------------

Here is the output from running that script...

: Step 1: Create the testing environment...
:
export TAR=/bin/tar TEST=~/test

echo; $TAR --version | grep 'GNU tar'

tar (GNU tar) 1.26

mkdir -p $TEST/from/foo $TEST/into
rm -rf $TEST/archive.tgz $TEST/into/*
date > $TEST/from/foo/bar

: Step 2: Show the contents of $TEST...
:
echo; cd $TEST; find . | sort | xargs ls -ld

drwxr-x--- 4 olekshy olekshy 4096 Oct 20 18:52 ./
drwxr-x--- 3 olekshy olekshy 4096 Oct 20 18:37 ./from/
drwxr-x--- 2 olekshy olekshy 4096 Oct 20 18:37 ./from/foo/
-rw-r----- 1 olekshy olekshy   29 Oct 20 18:52 ./from/foo/bar
drwxr-x--- 2 olekshy olekshy 4096 Oct 20 18:52 ./into/

: Step 3: Create $TEST/archive.tgz...
:
cd $TEST/from; find .   \
                        \
    | $TAR -vczf $TEST/archive.tgz --files-from=- --no-recursion
./
./foo/
./foo/bar

: Step 4: Show the contents of archive.tgz...
:
cd $TEST; $TAR -tzf $TEST/archive.tgz
./
./foo/
./foo/bar

: Step 5: Extract files from archive.tgz using --files-from...
:
cd $TEST; $TAR -tzf $TEST/archive.tgz | ( cd $TEST/into;

    $TAR -vxzf $TEST/archive.tgz --files-from=- --no-recursion )
./
./foo/
./foo/bar
/bin/tar: ./foo: Not found in archive
/bin/tar: ./foo/bar: Not found in archive
/bin/tar: Exiting with failure status due to previous errors

: Step 6: Show the contents of $TEST...
:
echo; cd $TEST; find . | sort | xargs ls -ld

drwxr-x--- 4 olekshy olekshy 4096 Oct 20 18:52 ./
-rw-r----- 1 olekshy olekshy  195 Oct 20 18:52 ./archive.tgz
drwxr-x--- 3 olekshy olekshy 4096 Oct 20 18:37 ./from/
drwxr-x--- 2 olekshy olekshy 4096 Oct 20 18:37 ./from/foo/
-rw-r----- 1 olekshy olekshy   29 Oct 20 18:52 ./from/foo/bar
drwxr-x--- 3 olekshy olekshy 4096 Oct 20 18:37 ./into/
drwxr-x--- 2 olekshy olekshy 4096 Oct 20 18:37 ./into/foo/
-rw-r----- 1 olekshy olekshy   29 Oct 20 18:52 ./into/foo/bar

exit #------------------------------------------------------------------

Sincerely Yours,
Tony Olekshy
Avra Software Lab Inc.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]