Archive-Tar-Wrapper

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    file within the tarball. $file_or_stringref 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.

    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:

        $arch->add($logic_path, $stringref,
                   { perm => 0755, uid => 123, gid => 10 });

    If $file_or_stringref is a reference to a Unicode string, the "binmode"
    option has to be set to make sure the string gets written as proper
    UTF-8 into the tar file:

        $arch->add($logic_path, $stringref, { binmode => ":utf8" });

  perm_cp
    Copies the permissions from a file to another.

README  view on Meta::CPAN

    Sets the permission on a file.

    Expects as parameters:

    1.  The path to the file where the permissions should be applied to.

    2.  An array reference with the permissions (see "perm_set")

    Returns 1 if everything goes fine.

    Ignore errors here, as we can't change uid/gid unless we're the
    superuser (see LIMITATIONS section).

  remove
        $arch->remove($logic_path);

    Removes a file from the tarball. $logic_path is the virtual path of the
    file within the tarball.

  list_all
        my $items = $arch->list_all();

README  view on Meta::CPAN


    *   Filenames containing newlines are causing problems with the list
        iterators. To be fixed.

    *   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.

        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).

BUGS
    Archive::Tar::Wrapper doesn't currently handle filenames with embedded
    newlines.

  Microsoft Windows support
    Support on Microsoft Windows is limited.

lib/Archive/Tar/Wrapper.pm  view on Meta::CPAN


sub add {
    my ( $self, $rel_path, $path_or_stringref, $opts ) = @_;

    if ($opts) {
        unless ( ( ref($opts) ) and ( ref($opts) eq 'HASH' ) ) {
            LOGDIE "Option parameter given to add() not a hashref.";
        }
    }

    my ( $perm, $uid, $gid, $binmode );
    $perm    = $opts->{perm}    if defined $opts->{perm};
    $uid     = $opts->{uid}     if defined $opts->{uid};
    $gid     = $opts->{gid}     if defined $opts->{gid};
    $binmode = $opts->{binmode} if defined $opts->{binmode};

    my $target     = File::Spec->catfile( $self->{tardir}, $rel_path );
    my $target_dir = dirname($target);

    unless ( -d $target_dir ) {
        if ( ref($path_or_stringref) ) {
            $self->add( dirname($rel_path), dirname($target_dir) );
        }
        else {

lib/Archive/Tar/Wrapper.pm  view on Meta::CPAN

    else {
        copy $path_or_stringref, $target
          or LOGDIE "Can't copy $path_or_stringref to $target ($!)";
    }

    if ( defined $uid ) {
        chown $uid, -1, $target
          or LOGDIE "Can't chown $target uid to $uid ($!)";
    }

    if ( defined $gid ) {
        chown -1, $gid, $target
          or LOGDIE "Can't chown $target gid to $gid ($!)";
    }

    if ( defined $perm ) {
        chmod $perm, $target
          or LOGDIE "Can't chmod $target to $perm ($!)";
    }

    if (    not defined $uid
        and not defined $gid
        and not defined $perm
        and not ref($path_or_stringref) )
    {
        perm_cp( $path_or_stringref, $target )
          or LOGDIE "Can't perm_cp $path_or_stringref to $target ($!)";
    }

    return 1;
}

lib/Archive/Tar/Wrapper.pm  view on Meta::CPAN

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.

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:

    $arch->add($logic_path, $stringref,
               { perm => 0755, uid => 123, gid => 10 });

If $file_or_stringref is a reference to a Unicode string, the C<binmode>
option has to be set to make sure the string gets written as proper UTF-8
into the tar file:

    $arch->add($logic_path, $stringref, { binmode => ":utf8" });

=head2 perm_cp

Copies the permissions from a file to another.

lib/Archive/Tar/Wrapper.pm  view on Meta::CPAN

The path to the file where the permissions should be applied to.

=item 2.

An array reference with the permissions (see C<perm_set>)

=back

Returns 1 if everything goes fine.

Ignore errors here, as we can't change uid/gid unless we're the superuser (see LIMITATIONS section).

=head2 remove

    $arch->remove($logic_path);

Removes a file from the tarball. C<$logic_path> is the virtual path
of the file within the tarball.

=head2 list_all

lib/Archive/Tar/Wrapper.pm  view on Meta::CPAN

iterators. To be fixed.

=item *

If you ask B<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.

This approach has limitations when it comes to file permissions: If the file to
be added belongs to a different user/group, B<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 B<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).

=back

=head1 BUGS

B<Archive::Tar::Wrapper> doesn't currently handle filenames with embedded
newlines.



( run in 0.604 second using v1.01-cache-2.11-cpan-5735350b133 )