.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Archive::Tar::Wrapper 3pm" .TH Archive::Tar::Wrapper 3pm "2015-05-29" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Archive::Tar::Wrapper \- API wrapper around the 'tar' utility .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Archive::Tar::Wrapper; \& \& my $arch = Archive::Tar::Wrapper\->new(); \& \& # Open a tarball, expand it into a temporary directory \& $arch\->read("archive.tgz"); \& \& # Iterate over all entries in the archive \& $arch\->list_reset(); # Reset Iterator \& # Iterate through archive \& while(my $entry = $arch\->list_next()) { \& my($tar_path, $phys_path) = @$entry; \& print "$tar_path\en"; \& } \& \& # Get a huge list with all entries \& for my $entry (@{$arch\->list_all()}) { \& my($tar_path, $real_path) = @$entry; \& print "Tarpath: $tar_path Tempfile: $real_path\en"; \& } \& \& # Add a new entry \& $arch\->add($logic_path, $file_or_stringref); \& \& # Remove an entry \& $arch\->remove($logic_path); \& \& # Find the physical location of a temporary file \& my($tmp_path) = $arch\->locate($tar_path); \& \& # Create a tarball \& $arch\->write($tarfile, $compress); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Archive::Tar::Wrapper is an \s-1API\s0 wrapper around the 'tar' command line utility. It never stores anything in memory, but works on temporary directory structures on disk instead. It provides a mapping between the logical paths in the tarball and the 'real' files in the temporary directory on disk. .PP It differs from Archive::Tar in two ways: .IP "\(bu" 4 Archive::Tar::Wrapper doesn't hold anything in memory. Everything is stored on disk. .IP "\(bu" 4 Archive::Tar::Wrapper is 100% compliant with the platform's \f(CW\*(C`tar\*(C'\fR utility, because it uses it internally. .SH "METHODS" .IX Header "METHODS" .ie n .IP "\fBmy \fB$arch\fB = Archive::Tar::Wrapper\->\f(BInew()\fB\fR" 4 .el .IP "\fBmy \f(CB$arch\fB = Archive::Tar::Wrapper\->\f(BInew()\fB\fR" 4 .IX Item "my $arch = Archive::Tar::Wrapper->new()" Constructor for the tar wrapper class. Finds the \f(CW\*(C`tar\*(C'\fR executable by searching \f(CW\*(C`PATH\*(C'\fR and returning the first hit. In case you want to use a different tar executable, you can specify it as a parameter: .Sp .Vb 1 \& my $arch = Archive::Tar::Wrapper\->new(tar => \*(Aq/path/to/tar\*(Aq); .Ve .Sp Since \f(CW\*(C`Archive::Tar::Wrapper\*(C'\fR creates temporary directories to store tar data, the location of the temporary directory can be specified: .Sp .Vb 1 \& my $arch = Archive::Tar::Wrapper\->new(tmpdir => \*(Aq/path/to/tmpdir\*(Aq); .Ve .Sp Tremendous performance increases can be achieved if the temporary directory is located on a ram disk. Check the \*(L"Using \s-1RAM\s0 Disks\*(R" section below for details. .Sp Additional options can be passed to the \f(CW\*(C`tar\*(C'\fR command by using the \&\f(CW\*(C`tar_read_options\*(C'\fR and \f(CW\*(C`tar_write_options\*(C'\fR parameters. Example: .Sp .Vb 3 \& my $arch = Archive::Tar::Wrapper\->new( \& tar_read_options => "p" \& ); .Ve .Sp will use \f(CW\*(C`tar xfp archive.tgz\*(C'\fR to extract the tarball instead of just \&\f(CW\*(C`tar xf archive.tgz\*(C'\fR. Gnu tar supports even more options, these can be passed in via .Sp .Vb 3 \& my $arch = Archive::Tar::Wrapper\->new( \& tar_gnu_read_options => ["\-\-numeric\-owner"], \& ); .Ve .Sp Similarily, \f(CW\*(C`tar_gnu_write_options\*(C'\fR can be used to provide additional options for Gnu tar implementations. For example, the tar object .Sp .Vb 3 \& my $tar = Archive::Tar::Wrapper\->new( \& tar_gnu_write_options => ["\-\-exclude=foo"], \& ); .Ve .Sp will call the \f(CW\*(C`tar\*(C'\fR utility internally like .Sp .Vb 1 \& tar cf tarfile \-\-exclude=foo ... .Ve .Sp when the \f(CW\*(C`write\*(C'\fR method gets called. .Sp By default, the \f(CW\*(C`list_*()\*(C'\fR functions will return only file entries. Directories will be suppressed. To have \f(CW\*(C`list_*()\*(C'\fR return directories as well, use .Sp .Vb 3 \& my $arch = Archive::Tar::Wrapper\->new( \& dirs => 1 \& ); .Ve .Sp If more files are added to a tarball than the command line can handle, \&\f(CW\*(C`Archive::Tar::Wrapper\*(C'\fR will switch from using the command .Sp .Vb 1 \& tar cfv tarfile file1 file2 file3 ... .Ve .Sp to .Sp .Vb 1 \& tar cfv tarfile \-T filelist .Ve .Sp where \f(CW\*(C`filelist\*(C'\fR is a file containing all file to be added. The default for this switch is 512, but it can be changed by setting the parameter \&\f(CW\*(C`max_cmd_line_args\*(C'\fR: .Sp .Vb 3 \& my $arch = Archive::Tar::Wrapper\->new( \& max_cmd_line_args => 1024 \& ); .Ve .ie n .IP "\fB\fB$arch\fB\->read(""archive.tgz"")\fR" 4 .el .IP "\fB\f(CB$arch\fB\->read(``archive.tgz'')\fR" 4 .IX Item "$arch->read(archive.tgz)" \&\f(CW\*(C`read()\*(C'\fR opens the given tarball, expands it into a temporary directory and returns 1 on success und \f(CW\*(C`undef\*(C'\fR on failure. The temporary directory holding the tar data gets cleaned up when \f(CW$arch\fR goes out of scope. .Sp \&\f(CW\*(C`read\*(C'\fR handles both compressed and uncompressed files. To find out if a file is compressed or uncompressed, it tries to guess by extension, then by checking the first couple of bytes in the tarfile. .Sp If only a limited number of files is needed from a tarball, they can be specified after the tarball name: .Sp .Vb 1 \& $arch\->read("archive.tgz", "path/file.dat", "path/sub/another.txt"); .Ve .Sp The file names are passed unmodified to the \f(CW\*(C`tar\*(C'\fR command, make sure that the file paths match exactly what's in the tarball, otherwise \&\f(CW\*(C`read()\*(C'\fR will fail. .ie n .IP "\fB\fB$arch\fB\->\f(BIlist_reset()\fB\fR" 4 .el .IP "\fB\f(CB$arch\fB\->\f(BIlist_reset()\fB\fR" 4 .IX Item "$arch->list_reset()" Resets the list iterator. To be used before the first call to \&\fB\f(CB$arch\fB\-\fR\fIlist_next()\fR>. .ie n .IP "\fBmy($tar_path, \fB$phys_path\fB, \f(BI$type\fB) = \f(CB$arch\fB\->\f(BIlist_next()\fB\fR" 4 .el .IP "\fBmy($tar_path, \f(CB$phys_path\fB, \f(CB$type\fB) = \f(CB$arch\fB\->\f(BIlist_next()\fB\fR" 4 .IX Item "my($tar_path, $phys_path, $type) = $arch->list_next()" Returns the next item in the tarfile. It returns a list of three scalars: the relative path of the item in the tarfile, the physical path to the unpacked file or directory on disk, and the type of the entry (f=file, d=directory, l=symlink). Note that by default, Archive::Tar::Wrapper won't display directories, unless the \f(CW\*(C`dirs\*(C'\fR parameter is set when running the constructor. .ie n .IP "\fBmy \fB$items\fB = \f(BI$arch\fB\->\f(BIlist_all()\fB\fR" 4 .el .IP "\fBmy \f(CB$items\fB = \f(CB$arch\fB\->\f(BIlist_all()\fB\fR" 4 .IX Item "my $items = $arch->list_all()" Returns a reference to a (possibly huge) array of items in the tarfile. Each item is a reference to an array, containing two elements: the relative path of the item in the tarfile and the physical path to the unpacked file or directory on disk. .Sp To iterate over the list, the following construct can be used: .Sp .Vb 5 \& # Get a huge list with all entries \& for my $entry (@{$arch\->list_all()}) { \& my($tar_path, $real_path) = @$entry; \& print "Tarpath: $tar_path Tempfile: $real_path\en"; \& } .Ve .Sp If the list of items in the tarfile is big, use \f(CW\*(C`list_reset()\*(C'\fR and \&\f(CW\*(C`list_next()\*(C'\fR instead of \f(CW\*(C`list_all\*(C'\fR. .ie n .IP "\fB\fB$arch\fB\->add($logic_path, \f(BI$file_or_stringref\fB, [$options])\fR" 4 .el .IP "\fB\f(CB$arch\fB\->add($logic_path, \f(CB$file_or_stringref\fB, [$options])\fR" 4 .IX Item "$arch->add($logic_path, $file_or_stringref, [$options])" Add a new file to the tarball. \f(CW$logic_path\fR is the virtual path of the file within the tarball. \f(CW$file_or_stringref\fR is either a scalar, in which case it holds the physical path of a file on disk to be transferred (i.e. copied) to the tarball. Or it is a reference to a scalar, in which case its content is interpreted to be the data of the file. .Sp If no additional parameters are given, permissions and user/group id settings of a file to be added are copied. If you want different settings, specify them in the options hash: .Sp .Vb 2 \& $arch\->add($logic_path, $stringref, \& { perm => 0755, uid => 123, gid => 10 }); .Ve .Sp If \f(CW$file_or_stringref\fR is a reference to a Unicode string, the \f(CW\*(C`binmode\*(C'\fR option has to be set to make sure the string gets written as proper \s-1UTF\-8\s0 into the tarfile: .Sp .Vb 1 \& $arch\->add($logic_path, $stringref, { binmode => ":utf8" }); .Ve .ie n .IP "\fB\fB$arch\fB\->remove($logic_path)\fR" 4 .el .IP "\fB\f(CB$arch\fB\->remove($logic_path)\fR" 4 .IX Item "$arch->remove($logic_path)" Removes a file from the tarball. \f(CW$logic_path\fR is the virtual path of the file within the tarball. .ie n .IP "\fB\fB$arch\fB\->locate($logic_path)\fR" 4 .el .IP "\fB\f(CB$arch\fB\->locate($logic_path)\fR" 4 .IX Item "$arch->locate($logic_path)" Finds the physical location of a file, specified by \f(CW$logic_path\fR, which is the virtual path of the file within the tarball. Returns a path to the temporary file \f(CW\*(C`Archive::Tar::Wrapper\*(C'\fR created to manipulate the tarball on disk. .ie n .IP "\fB\fB$arch\fB\->write($tarfile, \f(BI$compress\fB)\fR" 4 .el .IP "\fB\f(CB$arch\fB\->write($tarfile, \f(CB$compress\fB)\fR" 4 .IX Item "$arch->write($tarfile, $compress)" Write out the tarball by tarring up all temporary files and directories and store it in \f(CW$tarfile\fR on disk. If \f(CW$compress\fR holds a true value, compression is used. .ie n .IP "\fB\fB$arch\fB\->\f(BItardir()\fB\fR" 4 .el .IP "\fB\f(CB$arch\fB\->\f(BItardir()\fB\fR" 4 .IX Item "$arch->tardir()" Return the directory the tarball was unpacked in. This is sometimes useful to play dirty tricks on \f(CW\*(C`Archive::Tar::Wrapper\*(C'\fR by mass-manipulating unpacked files before wrapping them back up into the tarball. .ie n .IP "\fB\fB$arch\fB\->\f(BIis_gnu()\fB\fR" 4 .el .IP "\fB\f(CB$arch\fB\->\f(BIis_gnu()\fB\fR" 4 .IX Item "$arch->is_gnu()" Checks if the tar executable is a \s-1GNU\s0 tar by running 'tar \-\-version' and parsing the output for \*(L"\s-1GNU\*(R".\s0 .SH "Using RAM Disks" .IX Header "Using RAM Disks" On Linux, it's quite easy to create a \s-1RAM\s0 disk and achieve tremendous speedups while untarring or modifying a tarball. You can either create the \s-1RAM\s0 disk by hand by running .PP .Vb 2 \& # mkdir \-p /mnt/myramdisk \& # mount \-t tmpfs \-o size=20m tmpfs /mnt/myramdisk .Ve .PP and then feeding the ramdisk as a temporary directory to Archive::Tar::Wrapper, like .PP .Vb 1 \& my $tar = Archive::Tar::Wrapper\->new( tmpdir => \*(Aq/mnt/myramdisk\*(Aq ); .Ve .PP or using Archive::Tar::Wrapper's built-in option 'ramdisk': .PP .Vb 6 \& my $tar = Archive::Tar::Wrapper\->new( \& ramdisk => { \& type => \*(Aqtmpfs\*(Aq, \& size => \*(Aq20m\*(Aq, # 20 MB \& }, \& ); .Ve .PP Only drawback with the latter option is that creating the \s-1RAM\s0 disk needs to be performed as root, which often isn't desirable for security reasons. For this reason, Archive::Tar::Wrapper offers a utility functions that mounts the ramdisk and returns the temporary directory it's located in: .PP .Vb 5 \& # Create new ramdisk (as root): \& my $tmpdir = Archive::Tar::Wrapper\->ramdisk_mount( \& type => \*(Aqtmpfs\*(Aq, \& size => \*(Aq20m\*(Aq, # 20 MB \& ); \& \& # Delete a ramdisk (as root): \& Archive::Tar::Wrapper\->ramdisk_unmount(); .Ve .PP Optionally, the \f(CW\*(C`ramdisk_mount()\*(C'\fR command accepts a \f(CW\*(C`tmpdir\*(C'\fR parameter pointing to a temporary directory for the ramdisk if you wish to set it yourself instead of letting Archive::Tar::Wrapper create it automatically. .SH "KNOWN LIMITATIONS" .IX Header "KNOWN LIMITATIONS" .IP "\(bu" 4 Currently, only \f(CW\*(C`tar\*(C'\fR programs supporting the \f(CW\*(C`z\*(C'\fR option (for compressing/decompressing) are supported. Future version will use \&\f(CW\*(C`gzip\*(C'\fR alternatively. .IP "\(bu" 4 Currently, you can't add empty directories to a tarball directly. You could add a temporary file within a directory, and then \&\f(CW\*(C`remove()\*(C'\fR the file. .IP "\(bu" 4 If you delete a file, the empty directories it was located in stay in the tarball. You could try to \f(CW\*(C`locate()\*(C'\fR them and delete them. This will be fixed, though. .IP "\(bu" 4 Filenames containing newlines are causing problems with the list iterators. To be fixed. .IP "\(bu" 4 If you ask Archive::Tar::Wrapper to add a file to a tarball, it copies it into a temporary directory and then calls the system tar to wrap up that directory into a tarball. .Sp This approach has limitations when it comes to file permissions: If the file to be added belongs to a different user/group, Archive::Tar::Wrapper will adjust the uid/gid/permissions of the target file in the temporary directory to reflect the original file's settings, to make sure the system tar will add it like that to the tarball, just like a regular tar run on the original file would. But this will fail of course if the original file's uid is different from the current user's, unless the script is running with superuser rights. The tar program by itself (without Archive::Tar::Wrapper) works differently: It'll just make a note of a file's uid/gid/permissions in the tarball (which it can do without superuser rights) and upon extraction, it'll adjust the permissions of newly generated files if the \-p option is given (default for superuser). .SH "BUGS" .IX Header "BUGS" Archive::Tar::Wrapper doesn't currently handle filenames with embedded newlines. .SH "LEGALESE" .IX Header "LEGALESE" Copyright 2005 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. .SH "AUTHOR" .IX Header "AUTHOR" 2005, Mike Schilli