view release on metacpan or search on metacpan
VERSION
version 2.09
SYNOPSIS
use Archive::Ar::Libarchive;
my $ar = Archive::Ar->new('libfoo.a');
$ar->add_data('newfile.txt', 'some contents', { uid => 101, gid => 102 });
$ar->add_files('./bar.tar.gz', 'bat.pl');
$ar->remove('file1', 'file2');
my $content = $ar->get_content('file3')->{data};
my @files = $ar->list_files;
$ar->write('libbar.a');
Changes the name of a file in the in-memory archive.
chmod
$ar->chmod($filename, $mode);
Change the permission mode of the member to $mode.
chown
$ar->chown($filename, $uid, $gid);
$ar->chown($filename, $uid);
Change the ownership of the member to user id $udi and (optionally)
group id $gid. Negative id values are ignored.
remove
my $count = $ar->remove(@pathnames);
my $count = $ar->remove(\@pathnames);
The remove method takes a filenames as a list or as an arrayref, and
removes them, one at a time, from the Archive::Ar object. This returns
the number of files successfully removed from the archive.
$ar->add_files(@filenames);
$ar->add_files(\@filenames);
Takes an array or an arrayref of filenames to add to the ar archive, in
order. The filenames can be paths to files, in which case the path
information is stripped off. Filenames longer than 16 characters are
truncated when written to disk in the format, so keep that in mind when
adding files.
Due to the nature of the ar archive format,
Archive::Ar::Libarchive#add_files will store the uid, gid, mode, size,
and creation date of the file as returned by stat.
returns the number of files successfully added, or undef on failure.
add_data
my $size = $ar->add_data($filename, $data, $filedata);
Takes an filename and a set of data to represent it. Unlike
Archive::Ar::Libarchive#add_files, Archive::Ar::Libarchive#add_data is
a virtual add, and does not require data on disk to be present. The
data is a hash that looks like:
$filedata = {
uid => $uid, #defaults to zero
gid => $gid, #defaults to zero
date => $date, #date in epoch seconds. Defaults to now.
mode => $mode, #defaults to 0100644;
};
You cannot add_data over another file however. This returns the file
length in bytes if it is successful, undef otherwise.
write
my $content = $ar->write;
The file name
date
The file date (in epoch seconds)
uid
The uid of the file
gid
The gid of the file
mode
The mode permissions
size
The size (in bytes) of the file
data
lib/Archive/Ar/Libarchive.pm view on Meta::CPAN
sub chmod
{
my($self, $filename, $mode) = @_;
$self->_chmod($filename, $mode + 0 eq $mode ? $mode : oct($mode));
}
sub chown
{
my($self, $filename, $uid, $gid) = @_;
$self->_chown($filename, $uid, $gid);
}
sub remove
{
my $self = shift;
my $count = 0;
foreach my $pathname (@{ ref $_[0] ? $_[0] : \@_ })
{
$count += $self->_remove($pathname);
lib/Archive/Ar/Libarchive.pm view on Meta::CPAN
binmode $fh;
# TODO: we don't check for error on the actual
# read operation (but then nethier does
# Archive::Ar).
my $data = do { local $/; <$fh> };
close $fh;
$self->add_data(File::Basename::basename($filename), $data, {
date => $props[9],
uid => $props[4],
gid => $props[5],
mode => $props[2],
size => length $data,
});
$count++;
}
return unless $count;
$count;
}
sub add_data
{
my($self, $filename, $data, $filedata) = @_;
$filedata ||= {};
$self->_add_data($filename, $data, $filedata->{uid} || 0, $filedata->{gid} || 0, $filedata->{date} || time, $filedata->{mode} || oct(100644));
use bytes;
length $data;
}
sub write
{
my($self, $filename) = @_;
if(defined $filename)
{
lib/Archive/Ar/Libarchive.pm view on Meta::CPAN
=head1 VERSION
version 2.09
=head1 SYNOPSIS
use Archive::Ar::Libarchive;
my $ar = Archive::Ar->new('libfoo.a');
$ar->add_data('newfile.txt', 'some contents', { uid => 101, gid => 102 });
$ar->add_files('./bar.tar.gz', 'bat.pl');
$ar->remove('file1', 'file2');
my $content = $ar->get_content('file3')->{data};
my @files = $ar->list_files;
$ar->write('libbar.a');
lib/Archive/Ar/Libarchive.pm view on Meta::CPAN
Changes the name of a file in the in-memory archive.
=head2 chmod
$ar->chmod($filename, $mode);
Change the permission mode of the member to C<$mode>.
=head2 chown
$ar->chown($filename, $uid, $gid);
$ar->chown($filename, $uid);
Change the ownership of the member to user id C<$udi> and (optionally)
group id C<$gid>. Negative id values are ignored.
=head2 remove
my $count = $ar->remove(@pathnames);
my $count = $ar->remove(\@pathnames);
The remove method takes a filenames as a list or as an arrayref, and removes
them, one at a time, from the Archive::Ar object. This returns the number
of files successfully removed from the archive.
lib/Archive/Ar/Libarchive.pm view on Meta::CPAN
$ar->add_files(@filenames);
$ar->add_files(\@filenames);
Takes an array or an arrayref of filenames to add to the ar archive,
in order. The filenames can be paths to files, in which case the path
information is stripped off. Filenames longer than 16 characters are
truncated when written to disk in the format, so keep that in mind
when adding files.
Due to the nature of the ar archive format,
L<Archive::Ar::Libarchive#add_files> will store the uid, gid, mode,
size, and creation date of the file as returned by
L<stat|perlfunc#stat>.
returns the number of files successfully added, or C<undef> on failure.
=head2 add_data
my $size = $ar->add_data($filename, $data, $filedata);
Takes an filename and a set of data to represent it. Unlike
L<Archive::Ar::Libarchive#add_files>,
L<Archive::Ar::Libarchive#add_data> is a virtual add, and does not
require data on disk to be present. The data is a hash that looks like:
$filedata = {
uid => $uid, #defaults to zero
gid => $gid, #defaults to zero
date => $date, #date in epoch seconds. Defaults to now.
mode => $mode, #defaults to 0100644;
};
You cannot add_data over another file however. This returns the file
length in bytes if it is successful, C<undef> otherwise.
=head2 write
my $content = $ar->write;
lib/Archive/Ar/Libarchive.pm view on Meta::CPAN
The file name
=item date
The file date (in epoch seconds)
=item uid
The uid of the file
=item gid
The gid of the file
=item mode
The mode permissions
=item size
The size (in bytes) of the file
=item data
lib/Archive/Ar/Libarchive.xs view on Meta::CPAN
if((*entry)->next == NULL)
break;
entry = &((*entry)->next);
}
OUTPUT:
RETVAL
void
_add_data(self,filename,data,uid,gid,date,mode)
struct ar *self
const char *filename
SV *data
__LA_INT64_T uid
__LA_INT64_T gid
time_t date
int mode
CODE:
struct ar_entry **entry;
char *buffer;
entry = &(self->first);
while(*entry != NULL)
{
entry = &((*entry)->next);
}
Newx((*entry), 1, struct ar_entry);
(*entry)->entry = archive_entry_new();
archive_entry_set_pathname((*entry)->entry, filename);
archive_entry_set_uid((*entry)->entry, uid);
archive_entry_set_gid((*entry)->entry, gid);
archive_entry_set_mtime((*entry)->entry, date, date);
archive_entry_set_mode((*entry)->entry, mode);
(*entry)->next = NULL;
(*entry)->is_symbol_table = 0;
if(self->opt_symbols != NULL && !strcmp(SvPV_nolen(self->opt_symbols), filename))
(*entry)->is_symbol_table = 1;
buffer = SvPV(data, (*entry)->data_size);
archive_entry_set_size((*entry)->entry, (*entry)->data_size);
lib/Archive/Ar/Libarchive.xs view on Meta::CPAN
entry = ar_find_by_name(self, filename);
if(entry != NULL)
{
hv = newHV();
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-value"
hv_store(hv, "name", 4, newSVpv(filename, strlen(filename)), 0);
hv_store(hv, "date", 4, newSVi64(archive_entry_mtime(entry->entry)), 0);
hv_store(hv, "uid", 3, newSVi64(archive_entry_uid(entry->entry)), 0);
hv_store(hv, "gid", 3, newSVi64(archive_entry_gid(entry->entry)), 0);
hv_store(hv, "mode", 4, newSViv(archive_entry_mode(entry->entry)), 0);
hv_store(hv, "size", 4, newSViv(entry->data_size), 0);
hv_store(hv, "data", 4, newSVpv(entry->data, entry->data_size), 0);
#pragma clang diagnostic pop
RETVAL = newRV_noinc((SV*)hv);
}
else
{
XSRETURN_EMPTY;
lib/Archive/Ar/Libarchive.xs view on Meta::CPAN
}
else
{
XSRETURN_EMPTY;
}
OUTPUT:
RETVAL
int
_chown(self, filename, uid, gid)
struct ar *self
const char *filename
int uid
SV *gid
CODE:
struct ar_entry *entry;
entry = ar_find_by_name(self, filename);
if(entry != NULL)
{
if(uid >= 0)
archive_entry_set_uid(entry->entry, uid);
if(SvOK(gid) && SvIV(gid) >= 0)
{
archive_entry_set_gid(entry->entry, SvIV(gid));
}
}
else
{
XSRETURN_EMPTY;
}
const char *
_libarchive_version()
CODE:
t/20_add_data.t view on Meta::CPAN
my $ar = Archive::Ar::Libarchive->new;
is $ar->add_data("1", 'one'), 3, 'add_data';
is $ar->add_data("foo.txt", 'bar'), 3, 'add_data';
is $ar->add_data("2", 'two'), 3, 'add_data';
my $data = $ar->get_content('foo.txt');
is $data->{name}, 'foo.txt', 'name';
like $data->{date}, qr{^[1-9]\d*$}, 'date';
is $data->{uid}, 0, 'uid';
is $data->{gid}, 0, 'gid';
is $data->{mode}, 0100644, 'mode';
is $data->{data}, 'bar', 'data';
is $data->{size}, 3, 'size';
is $ar->get_content('goose'), undef, 'not found';
};
subtest 'non default values' => sub {
my $ar = Archive::Ar::Libarchive->new;
is $ar->add_data("1", 'one'), 3, 'add_data';
is $ar->add_data("foo.txt", 'barbaz', {
uid => 101,
gid => 201,
mode => 0644,
}), 6, 'add_data';
is $ar->add_data("2", 'two'), 3, 'add_data';
my $data = $ar->get_content('foo.txt');
is $data->{name}, 'foo.txt', 'name';
like $data->{date}, qr{^[1-9]\d*$}, 'date';
is $data->{uid}, 101, 'uid';
is $data->{gid}, 201, 'gid';
is $data->{mode}, 0644, 'mode';
is $data->{data}, 'barbaz', 'data';
is $data->{size}, 6, 'size';
is $ar->get_content('goose'), undef, 'not found';
};
t/40_mode.t view on Meta::CPAN
print $fh $content;
close $fh;
my $ar = Archive::Ar::Libarchive->new($file);
isa_ok $ar, 'Archive::Ar::Libarchive', 'object';
is_deeply [$ar->list_files], [qw(odd even)], 'list_files';
my $filedata = $ar->get_content('odd');
is $filedata->{name}, 'odd', 'file1, filedata/name';
is $filedata->{uid}, 2202, 'file1, filedata/uid';
is $filedata->{gid}, 2988, 'file1, filedata/gid';
is $filedata->{mode}, 0100644, 'file1, filedata/mode';
is $filedata->{date}, 1255532835, 'file1, filedata/date';
is $filedata->{size}, 11, 'file1, filedata/size';
is $filedata->{data}, "oddcontent\n", 'file1, filedata/data';
$filedata = $ar->get_content('even');
is $filedata->{name}, 'even', 'file2, filedata/name';
is $filedata->{uid}, 2202, 'file2, filedata/uid';
is $filedata->{gid}, 2988, 'file2, filedata/gid';
is $filedata->{mode}, 0100644, 'file2, filedata/mode';
is $filedata->{date}, 1255532831, 'file2, filedata/date';
is $filedata->{size}, 12, 'file2, filedata/size';
is $filedata->{data}, "evencontent\n", 'file2, filedata/data';
my ($nfh, $nfile) = tempfile(UNLINK => 1);
my $size = $ar->write($nfh);
is $size, 152, 'write size';
close $nfh;
my $dir = tempdir(CLEANUP => 1);
my $content = do {local $/ = undef; <DATA>};
umask 0;
my $ar = Archive::Ar::Libarchive->new();
$ar->read_memory($content) or diag $ar->error;
ok $ar->chown('foo.txt', 512), 'chown';
is $ar->get_content('foo.txt')->{uid}, 512, 'own is set';
is $ar->get_content('foo.txt')->{gid}, 1000, 'grp is unset';
ok $ar->chown('foo.txt', 750, 888), 'chown both uid and gid';
is $ar->get_content('foo.txt')->{uid}, 750, 'own is set';
is $ar->get_content('foo.txt')->{gid}, 888, 'grp is unset';
__DATA__
!<arch>
foo.txt 1384344423 1000 1000 100644 9 `
hi there
bar.txt 1384344423 1000 1000 100750 31 `
this is the content of bar.txt
undef $ar;
check_content(Archive::Ar::Libarchive->new($fn));
};
sub before
{
my $ar = Archive::Ar::Libarchive->new;
$ar->add_data("foo.txt", "foo content", {
uid => 101,
gid => 202,
date => 12345679,
mode => 0100640,
});
$ar->add_data("bar.txt", "bar content\nbar content\n", {
uid => 303,
gid => 404,
date => 123456798,
mode => 0100600,
});
$ar;
}
sub check_content
{
my $ar = shift;
subtest 'content' => sub {
plan tests => 3;
is_deeply scalar $ar->list_files, [qw( foo.txt bar.txt )], 'contains files foo and bar';
is_deeply $ar->get_content('foo.txt'), { name => 'foo.txt', date => 12345679, uid => 101, gid => 202, mode => 0100640, data => "foo content", size => 11 }, "foo content";
is_deeply $ar->get_content('bar.txt'), { name => 'bar.txt', date => 123456798, uid => 303, gid => 404, mode => 0100600, data => "bar content\nbar content\n", size => 24 }, "bar content";
};
}
xs/ppport.h view on Meta::CPAN
get_c_backtrace_dump|5.021001||V
get_context|5.006000|5.006000|nu
getc_unlocked|5.003007||Viu
get_cv|5.006000|5.003007|p
get_cvn_flags|5.009005|5.003007|p
get_cvs|5.011000|5.003007|p
getcwd_sv|5.007002|5.007002|
get_db_sub|||iu
get_debug_opts|5.008001||Viu
get_deprecated_property_msg|5.031011||cVniu
getegid|5.005000||Viu
getenv|5.005000||Viu
getenv_len|5.006000||Viu
GETENV_LOCK|5.033005||Viu
GETENV_PRESERVES_OTHER_THREAD|5.033005|5.033005|Vn
GETENV_UNLOCK|5.033005||Viu
geteuid|5.005000||Viu
getgid|5.005000||Viu
getgrent|5.009000||Viu
GETGRENT_R_HAS_BUFFER|5.008000||Viu
GETGRENT_R_HAS_FPTR|5.008000||Viu
GETGRENT_R_HAS_PTR|5.008000||Viu
GETGRENT_R_PROTO|5.008000|5.008000|Vn
getgrgid|5.009000||Viu
GETGRGID_R_HAS_BUFFER|5.008000||Viu
GETGRGID_R_HAS_PTR|5.008000||Viu
GETGRGID_R_PROTO|5.008000|5.008000|Vn
getgrnam|5.009000||Viu
GETGRNAM_R_HAS_BUFFER|5.008000||Viu
GETGRNAM_R_HAS_PTR|5.008000||Viu
GETGRNAM_R_PROTO|5.008000|5.008000|Vn
get_hash_seed|5.008001||Viu
gethostbyaddr|5.005000||Viu
GETHOSTBYADDR_R_HAS_BUFFER|5.008000||Viu
xs/ppport.h view on Meta::CPAN
KEY_fileno|5.003007||Viu
KEY_flock|5.003007||Viu
KEY_for|5.003007||Viu
KEY_foreach|5.003007||Viu
KEY_fork|5.003007||Viu
KEY_format|5.003007||Viu
KEY_formline|5.003007||Viu
KEY_ge|5.003007||Viu
KEY_getc|5.003007||Viu
KEY_getgrent|5.003007||Viu
KEY_getgrgid|5.003007||Viu
KEY_getgrnam|5.003007||Viu
KEY_gethostbyaddr|5.003007||Viu
KEY_gethostbyname|5.003007||Viu
KEY_gethostent|5.003007||Viu
KEY_getlogin|5.003007||Viu
KEY_getnetbyaddr|5.003007||Viu
KEY_getnetbyname|5.003007||Viu
KEY_getnetent|5.003007||Viu
KEY_getpeername|5.003007||Viu
KEY_getpgrp|5.003007||Viu
xs/ppport.h view on Meta::CPAN
Perl_pp_ftdir|5.013009||Viu
Perl_pp_fteexec|5.013009||Viu
Perl_pp_fteowned|5.013009||Viu
Perl_pp_fteread|5.013009||Viu
Perl_pp_ftewrite|5.013009||Viu
Perl_pp_ftfile|5.013009||Viu
Perl_pp_ftmtime|5.013009||Viu
Perl_pp_ftpipe|5.013009||Viu
Perl_pp_ftrexec|5.013009||Viu
Perl_pp_ftrwrite|5.013009||Viu
Perl_pp_ftsgid|5.013009||Viu
Perl_pp_ftsize|5.013009||Viu
Perl_pp_ftsock|5.013009||Viu
Perl_pp_ftsuid|5.013009||Viu
Perl_pp_ftsvtx|5.013009||Viu
Perl_pp_ftzero|5.013009||Viu
Perl_pp_getpeername|5.013009||Viu
Perl_pp_getsockname|5.013009||Viu
Perl_pp_ggrgid|5.013009||Viu
Perl_pp_ggrnam|5.013009||Viu
Perl_pp_ghbyaddr|5.013009||Viu
Perl_pp_ghbyname|5.013009||Viu
Perl_pp_gnbyaddr|5.013009||Viu
Perl_pp_gnbyname|5.013009||Viu
Perl_pp_gpbyname|5.013009||Viu
Perl_pp_gpbynumber|5.013009||Viu
Perl_pp_gpwnam|5.013009||Viu
Perl_pp_gpwuid|5.013009||Viu
Perl_pp_gsbyname|5.013009||Viu
xs/ppport.h view on Meta::CPAN
PERL_PRIgldbl|5.006000|5.006000|Vn
PerlProc_abort|5.005000||Viu
PerlProc_crypt|5.005000||Viu
PerlProc_DynaLoad|5.006000||Viu
PerlProc_execl|5.005000||Viu
PerlProc_execv|5.005000||Viu
PerlProc_execvp|5.005000||Viu
PerlProc__exit|5.005000||Viu
PerlProc_exit|5.005000||Viu
PerlProc_fork|5.006000||Viu
PerlProc_getegid|5.005000||Viu
PerlProc_geteuid|5.005000||Viu
PerlProc_getgid|5.005000||Viu
PerlProc_getlogin|5.005000||Viu
PerlProc_GetOSError|5.006000||Viu
PerlProc_getpid|5.006000||Viu
PerlProc_gettimeofday|5.008000||Viu
PerlProc_getuid|5.005000||Viu
PerlProc_kill|5.005000||Viu
PerlProc_killpg|5.005000||Viu
PerlProc_lasthost|5.007001||Viu
PerlProc_longjmp|5.005000||Viu
PerlProc_pause|5.005000||Viu
PerlProc_pclose|5.005000||Viu
PerlProc_pipe|5.005000||Viu
PerlProc_pipe_cloexec|5.027008||Viu
PerlProc_popen|5.005000||Viu
PerlProc_popen_list|5.007001||Viu
PerlProc_setgid|5.005000||Viu
PerlProc_setjmp|5.005000||Viu
PerlProc_setuid|5.005000||Viu
PerlProc_signal|5.005000||Viu
PerlProc_sleep|5.005000||Viu
PerlProc_spawnvp|5.008000||Viu
PerlProc_times|5.005000||Viu
PerlProc_wait|5.005000||Viu
PerlProc_waitpid|5.005000||Viu
perl_pthread_mutex_lock|5.023006||Viu
perl_pthread_mutex_unlock|5.023006||Viu
xs/ppport.h view on Meta::CPAN
PL_DBtrace|5.005000||pV
PL_DBtrace_iv|5.021005||Viu
PL_debstash|5.005000|5.003007|poVnu
PL_debug|5.005000||Viu
PL_debug_pad|5.007003||Viu
PL_defgv|5.004005|5.003007|p
PL_def_layerlist|5.007003||Viu
PL_defoutgv|5.005000||Viu
PL_defstash|5.005000||Viu
PL_delaymagic|5.005000||Viu
PL_delaymagic_egid|5.015008||Viu
PL_delaymagic_euid|5.015008||Viu
PL_delaymagic_gid|5.015008||Viu
PL_delaymagic_uid|5.015008||Viu
PL_destroyhook|5.010000||Viu
PL_diehook|5.005000|5.003007|poVnu
PL_Dir|5.006000||Viu
PL_dirty|5.005000|5.003007|poVnu
PL_doswitches|5.005000||Viu
PL_dowarn|5.005000||pV
PL_dumper_fd|5.009003||Viu
PL_dumpindent|5.006000||Viu
PL_dump_re_max_len|5.023008||Viu
xs/ppport.h view on Meta::CPAN
setbuf|5.003007||Viu
set_caret_X|5.019006||Viu
set_context|5.006000|5.006000|nu
setdefout|5.003007|5.003007|
SETERRNO|5.003007||Vi
setfd_cloexec|5.027008||Vniu
setfd_cloexec_for_nonsysfd|5.027008||Viu
setfd_cloexec_or_inhexec_by_sysfdness|5.027008||Viu
setfd_inhexec|5.027008||Vniu
setfd_inhexec_for_sysfd|5.027008||Viu
setgid|5.005000||Viu
setgrent|5.009000||Viu
SETGRENT_R_HAS_FPTR|5.008000||Viu
SETGRENT_R_PROTO|5.008000|5.008000|Vn
sethostent|5.005000||Viu
SETHOSTENT_R_PROTO|5.008000|5.008000|Vn
SETi|5.003007||Viu
setjmp|5.005000||Viu
setlinebuf|5.005000||Viu
setlocale|5.009000||Viu
setlocale_debug_string|5.027002||Vniu
xs/ppport.h view on Meta::CPAN
SET_NUMERIC_UNDERLYING|5.021010||Viu
set_numeric_underlying|5.027006||cViu
SETp|5.003007||Viu
set_padlist|5.021006||cVniu
setprotoent|5.005000||Viu
SETPROTOENT_R_PROTO|5.008000|5.008000|Vn
setpwent|5.009000||Viu
SETPWENT_R_HAS_FPTR|5.008000||Viu
SETPWENT_R_PROTO|5.008000|5.008000|Vn
set_regex_pv|5.029004||Viu
setregid|5.003007||Viu
setreuid|5.003007||Viu
SETs|5.003007||Viu
setservent|5.005000||Viu
SETSERVENT_R_PROTO|5.008000|5.008000|Vn
setsockopt|5.005000||Viu
setSTR_LEN|5.031005||Viu
SET_SVANY_FOR_BODYLESS_IV|5.023008||Viu
SET_SVANY_FOR_BODYLESS_NV|5.023008||Viu
SETTARG|5.003007||Viu
SET_THR|5.005000||Viu
xs/ppport.h view on Meta::CPAN
SvRV_set|5.009003|5.003007|p
sv_rvunweaken|5.027004|5.027004|
sv_rvweaken|5.006000|5.006000|
SvRVx|5.003007||Viu
SvRX|5.009005|5.003007|p
SvRXOK|5.009005|5.003007|p
SV_SAVED_COPY|5.009005||Viu
SvSCREAM|5.003007||Viu
SvSCREAM_off|5.003007||Viu
SvSCREAM_on|5.003007||Viu
sv_setgid|5.019001||Viu
sv_sethek|5.015004||cViu
sv_setiv|5.003007|5.003007|
sv_setiv_mg|5.004005|5.003007|p
SvSETMAGIC|5.003007|5.003007|
SvSetMagicSV|5.004000|5.004000|
SvSetMagicSV_nosteal|5.004000|5.004000|
sv_setnv|5.006000|5.003007|
sv_setnv_mg|5.006000|5.003007|p
sv_setpv|5.003007|5.003007|
sv_setpv_bufsize|5.025006|5.025006|