なぜPerlのIO:Compress :: Adapter :: Deflateがメモリが不足しているのですか?
-
28-09-2019 - |
質問
以下のタルボールに含まれるファイルのファイル許可を設定しようとしています。
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/5.10/i686-cygwin/io/compress/adapter/deflate.pm line 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