Subject: | Incorrect file permissions after extraction |
Hello,
Dir permissions are set as appropriate when extracting from an arch,
yet file permissions are not set.
To reproduce the issue test.zip can be used attached to the 14128 issue
(http://rt.cpan.org/NoAuth/Bug.html?id=14128)
It contains dir test_dir and file test_dir/test_file:
#ls -lR .
.:
total 4
dr-xr-xr-x 2 nobody nobody 4096 Aug 11 13:19 test_dir
./test_dir:
total 4
-r--r--r-- 1 nobody nobody 9 Aug 11 13:30 test_file
Do extractTree into /tmp:
#perl -MArchive::Zip -e' $z=Archive::Zip->new(); $z->read($ARGV[0]); $z->extractTree("", "/tmp/")' test.zip
Extracted file has -rw-r--r-- perm instead of original-r--r--r--:
#ls -l /tmp/test_dir/test_file
-rw-r--r-- 1 root root 9 Aug 11 13:30 /tmp/test_dir/test_file
The patch suggested for the issue 14128 (http://rt.cpan.org/NoAuth/Bug.html?id=14128)
corrects this issue either.
Yet if you use extractToFileNamed the problem remains:
#perl -MArchive::Zip -e' $z=Archive::Zip->new(); $z->read($ARGV[0]); $z->memberNamed("test_dir/test_file")->extractToFileNamed("/tmp/test_dir/test_file");' test.zip
# ls -l /tmp/test_dir/test_file
-rw-r--r-- 1 root root 9 Aug 11 13:30 /tmp/test_dir/test_file
I guess to correct this chmod() should be added in Archive::Zip::Member::extractToFileNamed before utime()
Suggested patch is attached.
Best regards
Alexey Kravchuk
diff -ru Archive-Zip-1.16.orig/lib/Archive/Zip.pm Archive-Zip-1.16/lib/Archive/Zip.pm
--- Archive-Zip-1.16.orig/lib/Archive/Zip.pm 2005-08-12 13:25:19.136143089 +0400
+++ Archive-Zip-1.16/lib/Archive/Zip.pm 2005-08-12 13:16:13.010874128 +0400
@@ -1821,6 +1821,7 @@
return _ioError("Can't open file $name for write") unless $status;
my $retval = $self->extractToFileHandle($fh);
$fh->close();
+ chmod $self->unixFileAttributes() & 07777, $name or warn "Can't chmod() $name: $!";
utime( $self->lastModTime(), $self->lastModTime(), $name );
return $retval;
}