Subject: | Add API to chmod a file. |
I'd like to request one more wafer-thin change: the abilty to chmod a
file in the archive.
Attached should be my attempt to do this.
Many thanks.
Subject: | Archive-Tar.patch |
diff --git a/lib/Archive/Tar.pm b/lib/Archive/Tar.pm
index e279b44..7ac20eb 100644
--- a/lib/Archive/Tar.pm
+++ b/lib/Archive/Tar.pm
@@ -70,6 +70,7 @@ Archive::Tar - module for manipulations of tar archives
$tar->rename('oldname', 'new/file/name');
$tar->chown('/', 'root');
$tar->chown('/', 'root:root');
+ $tar->chmod('/tmp', '1777');
$tar->write('files.tar'); # plain tar
$tar->write('files.tgz', COMPRESS_GZIP); # gzip compressed
@@ -1084,6 +1085,25 @@ sub rename {
return $entry->rename( $new );
}
+=head2 $tar->chmod( $file, $mode )
+
+Change mode of $file to $mode.
+
+Returns true on success and false on failure.
+
+=cut
+
+sub chmod {
+ my $self = shift;
+ my $file = shift; return unless defined $file;
+ my $mode = shift; return unless defined $mode && $mode =~ /^[0-7]{1,4}$/;
+ my @args = ("$mode");
+
+ my $entry = $self->_find_entry( $file ) or return;
+ my $x = $entry->chmod( @args );
+ return $x;
+}
+
=head2 $tar->chown( $file, $uname [, $gname] )
Change owner $file to $uname and $gname.
diff --git a/lib/Archive/Tar/File.pm b/lib/Archive/Tar/File.pm
index b700090..8fe1060 100644
--- a/lib/Archive/Tar/File.pm
+++ b/lib/Archive/Tar/File.pm
@@ -587,6 +587,22 @@ sub rename {
return 1;
}
+=head2 $bool = $file->chmod $mode)
+
+Change mode of $file to $mode. The mode can be a string or a number
+which is interpreted as octal whether or not a leading 0 is given.
+
+Returns true on success and false on failure.
+
+=cut
+
+sub chmod {
+ my $self = shift;
+ my $mode = shift; return unless defined $mode && $mode =~ /^[0-7]{1,4}$/;
+ $self->{mode} = oct($mode);
+ return 1;
+}
+
=head2 $bool = $file->chown( $user [, $group])
Change owner of $file to $user. If a $group is given that is changed
diff --git a/t/04_resolved_issues.t b/t/04_resolved_issues.t
index 7c4dd7c..45b7a91 100644
--- a/t/04_resolved_issues.t
+++ b/t/04_resolved_issues.t
@@ -110,6 +110,10 @@ use_ok( $FileClass );
ok( $tar->add_files( $in_file ),
" Added '$in_file'" );
+
+ ok( $tar->chmod( $in_file, '1777'),
+ " chmod 177 $in_file" );
+
ok( $tar->chown( $in_file, 'root' ),
" chown to root" );