Por que o IO da Perl: Compress :: Adaptador :: Deflate Ficando sem memória?
-
28-09-2019 - |
Pergunta
Estou tentando definir as permissões de arquivos contidas em um tarball com o seguinte:
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";
}
Mas quando o write()
O método é chamado, o script morre com o seguinte erro:
Fora da memória durante a solicitação "grande" de 268439552 bytes, o total sbrk () é 313298944 bytes em /usr/lib/perl5/5.10/i686-cygwin/io/compress/adapter/deflate.pm linha 43.
O tarball acionando esse erro é de 22 MB (59 MB não comprimido), portanto os números acima são um pouco alarmantes. Estou lidando com um bug em IO::Compress
? Existe algum tipo de solução alternativa neste caso? Estou usando o Perl 5.10.1 para i686-cygwin-thread-multi-64int.
Solução
Isso é um tiro no escuro, mas você pode tentar o seguinte 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);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow