[英]Why is Perl's IO:Compress::Adapter::Deflate running out of memory?
I'm trying to set the file permissions of files contained in a tarball with the following: 我正在尝试通过以下方式设置压缩包中包含的文件的文件权限:
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";
}
But when the write()
method is called, the script dies with the following error: 但是,当调用
write()
方法时,脚本死于以下错误:
Out of memory during "large" request for 268439552 bytes, total sbrk() is 313298944 bytes at /usr/lib/perl5/5.10/i686-cygwin/IO/Compress/Adapter/Deflate.pm line 43.
在“大”请求268439552字节期间内存不足,在/usr/lib/perl5/5.10/i686-cygwin/IO/Compress/Adapter/Deflate.pm第43行,总sbrk()为313298944字节。
The tarball triggering this error is 22MB (59MB uncompressed), so the numbers above are a little alarming. 触发此错误的压缩包是22MB(未压缩的59MB),因此上面的数字有点令人震惊。 Am I dealing with a bug in
IO::Compress
? 我正在处理
IO::Compress
的错误吗? Is there some kind of workaround in this case? 在这种情况下,有什么解决方法吗? I'm using perl 5.10.1 for i686-cygwin-thread-multi-64int.
我正在为i686-cygwin-thread-multi-64int使用perl 5.10.1。
This is a shot in the dark, but can you try the following script? 这是黑暗中的镜头,但是您可以尝试以下脚本吗?
#!/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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.