$ (cd src_dir; tar cvf - .) | (cd target_dir; tar xvf -)

Actually that's not what the original monk wants to do. Brother blyman wants to extract files inside a tar archive to a different location than the one they use inside the archive. For example, the archive contains /usr/bin/perl and he wants to be able to extract it to /usr/local/bin/perl. Your second example:

$ (cd tarfile_dir; tar xvf - tarball.tar) | (cd tgt_dir; tar xvf -)

Doesn't do much, because it extracts tarball.tar from a tar archive coming via STDIN, and the second tar does nothing.

Besides the problem already pointed out by Brothen blyman, I think there's a second one: permissions for directories are not preserved. If want to extract /usr/bin/perl to /usr/local/bin/perl, you'd like to preserve the permissions of at least bin. Inside the tarball there could be files as well as other little beasts, such as directories, fifos and devices. I was trying to come up with a solution that doesn't involve a temporary storage location but everything I've come up with has drawbacks (performance being the most common one). Looking at Archive::Tar, you can get a list of the files in the tar archive and then request the data for each of them. In principle you'll be doing something like:

my @files = $archive->get_files; foreach my $file (@files) { my $dst = compute_new($orig, $replacement, $file); save_data($file, $dst); }

The problem is of course what I have pointed out, namely getting the permissions right. save_data here of course handles permissions and all the little details. What I wanted to make clear is that this requires you to read the tarfile twice: once for the list of files and a second one for the actual data. A forward iterator kind of interface would be helpful here. You would just get the name of the current file and request its data if needed or just skip to the next file. That would allow for a solution that works with pipes.


In reply to Re: Re: tar_mv: move tar data as it's being extracted by mem
in thread tar_mv: move tar data as it's being extracted by belden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.