Archive-Ar-Libarchive
view release on metacpan or search on metacpan
2.00 2014-06-18 10:14:24 -0400
- this version serves primarily to bring the API in line with
Archive::Ar 2.00
- added methods
- set_opt
- get_opt
- clear
- get_data
- chmod
- chown
- type
- rename
- extract
- extract_filename
- error
- contains_file
- deprecated methods
- DEBUG
- set_output_format_bsd
- set_output_format_svr4
t/40_mode.t
t/45_content.t
t/50_remove.t
t/55_write.t
t/60_extract.t
t/65_gnu.t
t/66_gnu_symtab.t
t/70_bsd.t
t/basic.t
t/chmod.t
t/chown.t
t/clear.t
t/common.t
t/contains_file.t
t/error.t
t/extract_file.t
t/foo.ar
t/write.t
typemap
windows.yml
xs/perl_math_int64.c
it to false will has no effect.
same_perms
When setting file permissions, use the values in the archive
unchanged. If false, removes setuid bits and applies the user's
umask. Default is true.
In Archive::Ar this option is true for root only.
chown
Change the owners of extracted files, if possible. Default is true.
type
Archive type. May be GNU, BSD or COMMON, or undef if no archive has
been read. Defaults to the type of the archive read or undef.
symbols
$ar->rename($filename, $newname);
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
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
it to false will has no effect.
=item same_perms
When setting file permissions, use the values in the archive unchanged.
If false, removes setuid bits and applies the user's umask. Default
is true.
In L<Archive::Ar> this option is true for root only.
=item chown
Change the owners of extracted files, if possible. Default is true.
=item type
Archive type. May be GNU, BSD or COMMON, or undef if no archive
has been read. Defaults to the type of the archive read or C<undef>.
=item symbols
lib/Archive/Ar/Libarchive.pm view on Meta::CPAN
$ar->rename($filename, $newname);
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
lib/Archive/Ar/Libarchive.xs view on Meta::CPAN
struct ar_entry;
struct ar {
struct ar_entry *first;
SV *callback;
unsigned int opt_warn : 2;
unsigned int opt_chmod : 1;
unsigned int opt_same_perms : 1;
unsigned int opt_chown : 1;
unsigned int opt_type : 2;
SV *error;
SV *longmess;
SV *opt_symbols;
};
struct ar_entry {
struct archive_entry *entry;
const char *data;
size_t data_size;
struct ar_entry *next;
unsigned int is_symbol_table : 1;
};
static int ar_disk_options(struct ar *ar)
{
int flags = ARCHIVE_EXTRACT_TIME;
if(ar->opt_chown)
flags |= ARCHIVE_EXTRACT_OWNER;
if(ar->opt_same_perms)
flags |= ARCHIVE_EXTRACT_PERM;
return flags;
}
static void
ar_free_entry(struct ar_entry *entry)
{
archive_entry_free(entry->entry);
lib/Archive/Ar/Libarchive.xs view on Meta::CPAN
struct ar *self;
Newx(self, 1, struct ar);
self->first = NULL;
self->callback = NULL;
self->error = NULL;
self->longmess = NULL;
self->opt_symbols = NULL;
self->opt_warn = 0;
self->opt_chmod = 1; /* ignored */
self->opt_same_perms = 1; /* different: pp version this is true for root only */
self->opt_chown = 1;
ar_reset(self);
RETVAL = self;
OUTPUT:
RETVAL
int
set_opt(self, name, value)
struct ar *self
const char *name
SV *value
CODE:
if(!strcmp(name, "warn"))
RETVAL = self->opt_warn = SvIV(value);
else if(!strcmp(name, "chmod"))
RETVAL = self->opt_chmod = SvIV(value);
else if(!strcmp(name, "same_perms"))
RETVAL = self->opt_same_perms = SvIV(value);
else if(!strcmp(name, "chown"))
RETVAL = self->opt_chown = SvIV(value);
else if(!strcmp(name, "type"))
RETVAL = self->opt_type = SvIV(value);
else if(!strcmp(name, "symbols"))
self->opt_symbols = SvREFCNT_inc(value); /* TODO: make set_opt return void; maybe */
else
warn("unknown or unsupported option %s", name);
OUTPUT:
RETVAL
int
get_opt(self, name)
struct ar *self
const char *name
CODE:
if(!strcmp(name, "warn"))
RETVAL = self->opt_warn;
else if(!strcmp(name, "chmod"))
RETVAL = self->opt_chmod;
else if(!strcmp(name, "same_perms"))
RETVAL = self->opt_same_perms;
else if(!strcmp(name, "chown"))
RETVAL = self->opt_chown;
else if(!strcmp(name, "type"))
{
if(self->opt_type == ARCHIVE_AR_UNDEF)
XSRETURN_EMPTY;
else
RETVAL = self->opt_type;
}
else
warn("unknown or unsupported option %s", name);
OUTPUT:
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)
t/05_class.t view on Meta::CPAN
can_ok $mod, 'get_opt';
can_ok $mod, 'type';
can_ok $mod, 'clear';
can_ok $mod, 'read';
can_ok $mod, 'read_memory';
can_ok $mod, 'contains_file';
can_ok $mod, 'extract';
can_ok $mod, 'extract_file';
can_ok $mod, 'rename';
can_ok $mod, 'chmod';
can_ok $mod, 'chown';
can_ok $mod, 'remove';
can_ok $mod, 'list_files';
can_ok $mod, 'add_files';
can_ok $mod, 'add_data';
can_ok $mod, 'write';
can_ok $mod, 'get_content';
can_ok $mod, 'get_data';
can_ok $mod, 'get_handle';
can_ok $mod, 'error';
use Archive::Ar::Libarchive;
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 `
xs/ppport.h view on Meta::CPAN
KEY_binmode|5.003007||Viu
KEY_bless|5.003007||Viu
KEY_break|5.027008||Viu
KEY_caller|5.003007||Viu
KEY_catch|5.033007||Viu
KEY_chdir|5.003007||Viu
KEY_CHECK|5.006000||Viu
KEY_chmod|5.003007||Viu
KEY_chomp|5.003007||Viu
KEY_chop|5.003007||Viu
KEY_chown|5.003007||Viu
KEY_chr|5.003007||Viu
KEY_chroot|5.003007||Viu
KEY_close|5.003007||Viu
KEY_closedir|5.003007||Viu
KEY_cmp|5.003007||Viu
KEY_connect|5.003007||Viu
KEY_continue|5.003007||Viu
KEY_cos|5.003007||Viu
KEY_crypt|5.003007||Viu
KEY___DATA|5.003007||Viu
xs/ppport.h view on Meta::CPAN
Perl_isinf|5.007003|5.007003|n
Perl_isnan|5.006001|5.006001|n
PERL_IS_SUBWORD_ADDR|5.027007||Viu
PERL_JNP_TO_DECIMAL|5.033001||Viu
Perl_langinfo|5.027004|5.027004|n
PERL_LANGINFO_H|5.027004||Viu
PERL_LAST_5_18_0_INTERP_MEMBER|5.017009||Viu
Perl_ldexp|5.021003|5.021003|n
PerlLIO_access|5.005000||Viu
PerlLIO_chmod|5.005000||Viu
PerlLIO_chown|5.005000||Viu
PerlLIO_chsize|5.005000||Viu
PerlLIO_close|5.005000||Viu
PerlLIO_dup2|5.005000||Viu
PerlLIO_dup2_cloexec|5.027008||Viu
PerlLIO_dup|5.005000||Viu
PerlLIO_dup_cloexec|5.027008||Viu
PerlLIO_flock|5.005000||Viu
PerlLIO_fstat|5.005000||Viu
PerlLIO_ioctl|5.005000||Viu
PerlLIO_isatty|5.005000||Viu
( run in 1.687 second using v1.01-cache-2.11-cpan-71847e10f99 )