为什么Perl的IO:Compress :: Adapter :: Deflate用完了存储器?
-
28-09-2019 - |
题
我正在尝试设置Tarball中包含的文件的文件权限,但以下内容:
print "Checking $tgz_file... ";
my $edited = 0;
my $tarball = Archive::Tar->new($tgz_file);
my @items = $tarball->get_files();
foreach (@items) {
if ($_->is_dir && $_->mode != 0755) {
$_->mode(0755);
$edited = 1;
} elsif ($_->is_file && $_->mode != 0644) {
$_->mode(0644);
$edited = 1;
}
}
if ($edited) {
$tarball->write($tgz_file, COMPRESS_GZIP);
print "edited!\n";
} else {
print "no changes.\n";
}
但是当 write()
调用方法,脚本死于以下错误:
在对268439552字节的“大”请求期间的记忆中,总sbrk()为313298944字节,at/usr/lib/perl5/5.10/i686-cygwin/io/compress/compress/adapter/adapter/deflate/deflate.pm 43。
触发此错误的TARBALL为22MB(未压缩59MB),因此上面的数字有些令人震惊。我在处理一个错误吗 IO::Compress
?在这种情况下,有某种解决方法吗?我正在为i686-cygwin-thread-multi-64int使用Perl 5.10.1。
解决方案
这是在黑暗中拍摄的,但是您可以尝试以下脚本吗?
#!/usr/bin/perl
use strict; use warnings;
use Archive::Tar;
my $in = '...';
my $out = "edited-$in";
print "Checking $in ...\n";
my $out_archive = Archive::Tar->new;
my $edited;
my $next = Archive::Tar->iter($in);
while ( my $item = $next->() ) {
if ($item->is_dir and $item->mode != 0755) {
$item->mode(0755);
$edited = 1;
} elsif ($item->is_file and $item->mode != 0644) {
$item->mode(0644);
$edited = 1;
}
$out_archive->add_files( $item );
}
if ( $edited ) {
print "Writing $out ...\n";
$out_archive->write($out);
}
不隶属于 StackOverflow