[LUNI] Question about TAR...

Martin Maney maney at pobox.com
Sat Nov 2 16:21:07 CST 2002


On Sat, Nov 02, 2002 at 01:09:32PM -0800, Joe Frost wrote:

> --- gs-list <gs-list at glsrms.com> wrote:
> > Here's how the original question was posed:
> > 
> > lets say in snafu.tar i have /mnt/foo/blah, i want to extract 
> > /mnt/foo/blah/* to /blah, cwd is /blah how do i do that?

> You can't do that with tar.  Absolute paths are
> absolute paths.  Take a look into pax.

Never say never.  It would be an awful, ugly, innefficent kluge, but
you could do that using tar and some other tools not including rm or
mv.  Well, it might be useful to be able to use rm on O(1) scratch
files, but quite likely you could get this into a pipe without temp
files.  The data flow is something like this:

* Use tar's t operation to extract the paths of its contents
* filter these to extarct the pathnames that you want

  for the case where everything is under a single directory, as asked
  for here, tar itself can probably do the filtering.  it might even
  work for multiple subdirectories from the archived tree - the docs
  aren't explicit (or I'm looking at the wrong page in the fragmented
  info mess - why, oh why, did the FSF have to invent a documentation
  format that encourages all the worst aspects of Windows' online
  help, but with a much uglier interface?)  It probably works...

* for each wanted name, run tar with -x <pathname> -O
  redirect output to the destination path

  this is where I think some preprocessing that would leave a scratch
  file or two around would be useful; also, building directories as
  needed might be interestingly difficult otherwise!

Extracting n files from an archive of length m this way will read on
the order of n * m / 2 bytes (uhm, assuming tar stops reading after
extracting the target file with -x; if not, lose the factor of 1/2). 
If the m bytes of the input archive can live in memory buffers, that
might not be a problem.

Alternate approach with minimal cleanup:

* create symlinks for the unwanted directory components that lead to
  the desired destination

* list and filter contents as above (as above, tar may suffice here)

* just extract stuff - it will go where it belongs automagically

* cleanup the symlinks

  big difficulty here is making it safe from naming conflicts.  There
  are several approaches that could be used; using a dummy in /tmp is
  probably simplest.


Okay, stop me before I come up with an even uglier kluge!

-- 
To read a book, to think it over, and to write out notes
is a useful exercise; a book which will not repay some hard thought 
is not worth publishing.  -- Maria Mitchell




More information about the luni mailing list