Subject: | Issue with adding directories to a tar file not maintaining original permissions |
Date: | Wed, 14 Mar 2012 10:42:06 -0700 |
To: | bug-Archive-Tar-Wrapper [...] rt.cpan.org |
From: | Brian Lanier <brian [...] lanierfamily.net> |
Running Archive::Tar::Wrapper version "0.15" via CPAN
Centos 5.8
Perl Version 5.8.8
I am using this module to archive up directories and compress them.
Everything works great, however, directory permissions are not
preserved. File permissions are great. I also notice you cannot pass in
directories to the add method due to the use of the copy statement.
Directories get created fine by the mkpath call however, they don't get
sent to the permissions functions because they are made as a parent of
the file getting added.
I needed to be able to create an array of files and directories and loop
through the array, adding them to a tar archive. Currently, unless you
skip the directories, the add method will choke and die due to the copy.
The fix below allows you to send a directory to the add method. It is
minimal and I don't think it changes the method any other way. There is
probably a better way, but this works for me. I had to add in the second
mkpath call because it kept tripping up when the directory was added
before a file within the directory: primarily the top level directory.
Was trying to avoid unnecessary logic changes for now.
In my case, I am calling the method in the following way:
$tar = Archive::Tar::Wrapper->new();
find (sub { push @TAR_DIR_LIST, $File::Find::name }, $dir);
foreach $tar_element (@TAR_DIR_LIST) {
$tar->add($tar_element,$tar_element);
}
$logger->error("Error: Problem writing TAR FILE") unless
$tar->write($dir.$SUFFIX,$COMPRESS);
where $dir contains a path to the directory I want to archive.
If I am totally missing the point of the module, please let me know.
Advanced Novice with Perl, so there is always a better way.
Thanks
Brian
---- /admin/changes/Archive.Tar.Wrapper.orig.pm 2012-03-13
14:42:32.000000000 -0700
+++ /usr/lib/perl5/site_perl/5.8.8/Archive/Tar/Wrapper.pm
2012-03-14 10:35:28.000000000 -0700
@@ -178,8 +178,13 @@
print FILE $$path_or_stringref;
close FILE;
} else {
- copy $path_or_stringref, $target or
- LOGDIE "Can't copy $path_or_stringref to $target ($!)";
+ if ( -d $path_or_stringref) {
+ mkpath($target, 0, 0755) unless -d $target;
+
+ } else {
+ copy $path_or_stringref, $target or
+ LOGDIE "Can't copy $path_or_stringref to $target ($!)";
+ }
}
if(defined $uid) {