Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Archive:Tar appears to store absolute pathnames as relative pathnames

by Bloodnok (Vicar)
on Dec 11, 2009 at 13:04 UTC ( #812370=perlquestion: print w/ replies, xml ) Need Help??
Bloodnok has asked for the wisdom of the Perl Monks concerning the following question:

Good local time, most venerable brothers and sisters,

Not for the first time, I find myself seeking the benefit of your wisdom &/or experience...

Whilst developing a new script, I noticed that tar files (whether compressed, or not) created using Archive::Tar fails to preserve absolute paths - every absolute path I wrote to the archive was automagically converted to a relative path by virtue of having the leading slash removed.

I wondered whether anybody else had noticed this somewhat unexpected behaviour ? I can't believe that such a fundamental problem has gone unnoticed all this time...

perl -v is 5.8.8 & $Archive::Tar::VERSION is 1.32 - a situation I have to make the best of for reasons way beyond my control.

Thanking you all in advance ...

A user level that continues to overstate my experience :-))

Comment on Archive:Tar appears to store absolute pathnames as relative pathnames
Select or Download Code
Re: Archive:Tar appears to store absolute pathnames as relative pathnames
by Fox (Pilgrim) on Dec 11, 2009 at 13:21 UTC
    yea this is what also tar does.
    i.e. if you compress /home/users/you/dir/
    you will have home/users/you/dir

    unpacking it to / is the receiver choice. you can't force him to unpack on /

    UPDATE: ok, it looks like you can, on tar you must use -P, and it won't unpack to / if you don't also use -P when unpack
          ...if you compress /home/users/you/dir/ you will have home/users/you/dir

      Obviously it's a feature of the compression that I'd not noticed 'til now - a gotcha I'll be sure to remember from here on in...

      <c> ...you can't force him to unpack on /

      ..which, IMO, just goes to show that the use of compressed tar(1) files is not the way to go from the POV of software delivery where delivery of absolute files is frequently an immutable requirement.

      A user level that continues to overstate my experience :-))
      You can also compress using the -C option, to change to that directory, and then you will have relatives paths. for example: /home/users/you/dir I can compress using: tar -czf example.tar.gz -C /home/users/you dir And you will get a tar with the directory dir.
Re: Archive:Tar appears to store absolute pathnames as relative pathnames
by almut (Canon) on Dec 11, 2009 at 13:24 UTC
    ...fails to preserve absolute paths

    The regular tar program has the same (default) behavior (so it's not all that surprising).   (GNU-)tar, however, has an option to disable the feature (-P/--absolute-names : donít strip leading Ď/ís from file names). A cursory scan of the Archive::Tar docs did not locate anything similar, but maybe if you look more carefully, you'll find something...

    The idea is to just cd into the desired top-level directory before unpacking.

          The regular tar program has the same default) behavior...

      This isn't, or at least wasn't, the default behaviour on either Solaris or AIX ... or even HP-UX for that matter.

      A user level that continues to overstate my experience :-))
Re: Archive:Tar appears to store absolute pathnames as relative pathnames
by keszler (Priest) on Dec 11, 2009 at 13:28 UTC
    In the current version, Archive::Tar has INSECURE_EXTRACT_MODE:
    $Archive::Tar::INSECURE_EXTRACT_MODE This variable indicates whether Archive::Tar should allow files to be extracted outside their current working directory. Allowing this could have security implications, as a malicious tar archive could alter or replace any file the extracting user has permissions to. Therefor, the default is to not allow insecure extractions. If you trust the archive, or have other reasons to allow the archive to write files outside your current working directory, set this variable to true. Note that this is a backwards incompatible change from version 1.36 and before.
    So it appears that the issue has been addressed.

      Another clue in the documentation supporting the theory that Archive::Tar will support extracting absolute paths is the documentation for the Archive::Tar->extract_archive($file, $compressed) function:

      Extracts the contents of the tar file. The first argument can either be the name of the tar file to create or a reference to an open file handle (e.g. a GLOB reference). All relative paths in the tar file will be created underneath the current working directory.

      That implies that absolute paths have a different behavior--perhaps using the absolute path. You ought to give it a try and report back for posterity.

      ...roboticus

      Who really ought to try Archive::Tar sometime...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://812370]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-08-27 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls