Re: Compressed Tar : stop on first occurrence

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

 



Mauricio Silveira wrote:

> I'm wondering if there's any way to get tar to stop immediately after 
> the extraction of a file on compressed tar files. eg: I pack a big tgz 
> with the file index.txt first so that when I run "tar xf file.tgz 
> --occurrence index.txt" it extracts "index.txt" but proceeds reading the 
> file. I wish tar stopped after extracting the intended file.
> 
> I know it works for non-compressed tar archives....

--occurrence only works on files. When you extract a compressed
archive, tar spawns a separate gzip process connected via a pipe. The
effect is identical to:

	gzip -dc archive.tar.gz | tar xf - ...

Terminating while reading from a pipe will cause the writing process
to terminate abnormally (SIGPIPE, or if that is caught, EPIPE). This
can have undesirable side effects, so tar always reads until EOF when
reading from a pipe or socket.

You could disable this behaviour by removing the call to
sys_drain_input_pipe() from close_archive() in src/buffer.c.

The sys_drain_input_pipe() function (in src/system.c) is preceded by
the comment:

/* Manage to fully drain a pipe we might be reading, so to not break it on
   the producer after the EOF block.  FIXME: one of these days, GNU tar
   might become clever enough to just stop working, once there is no more
   work to do, we might have to revise this area in such time.  */

If you regularly want to extract individual members from an archive,
consider using an archive format which was designed for random access,
e.g. zip.

terry white wrote:

>     'man tar' offers:
> 
>        -T, --files-from F
>               get names to extract or create from file F
> 
> 
> : when I run "tar xf file.tgz --occurrence index.txt"
> 
>     HOWEVER , i'm using a gnu flavour 'tar', which does "not" list
> '--occurrence' as an option, so, the suggestion above may not apply ...

The --occurrence switch is relatively new; it's present in GNU tar
1.15.1. The -T switch has been around as long as I can remember, but
it doesn't help here.

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Newbie]     [Audio]     [Hams]     [Kernel Newbies]     [Util Linux NG]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Device Drivers]     [Samba]     [Video 4 Linux]     [Git]     [Fedora Users]

  Powered by Linux