Perl Archive::zip -- 文件未添加

标签 perl zip archive

我正在遍历目录树(颠覆备份)并将找到的每个文件和目录添加到 zip 文件中。这工作起来非常流畅。但是缺少两个文件。

sub zipFolder
{
    my $dir = 'D:\\SVN-Backup\\EnterpriseDataRepository\\20110502-0630';
    my $zip = Archive::Zip->new();
    my $zipped = $zip->addDirectory($dir);
    $zipped->desiredCompressionLevel( 9 );
    $zipped->desiredCompressionMethod( COMPRESSION_DEFLATED );
        print "Before find\n";
    find(\&zip_file, $dir);
    print "after find\n";
    die 'write error' unless $zip->writeToFileNamed('D:/SVN-Backup/CCBuild/backup.zip' ) == AZ_OK;

    sub zip_file 
    {
          print $File::Find::name;
          if ( -d $File::Find::name ) { # just grab directories, not files.
            $zip->addDirectory($File::Find::name);
            print " : dir\n";
         } else { #zip files
           print " : file\n";
           $zip->addFile($File::Find::name) != AZ_OK ||  print "couldn't add file \n";
         }

    }
}

文件 D:\SVN-Backup\20110502-0630/db/revprops/0/0 将不会添加到 zip 存档中。知道我可以做什么来添加这个文件吗?

...
D:\SVN-Backup\20110502-0630/db/uuid : file
D:\SVN-Backup\20110502-0630/db/revprops : dir
D:\SVN-Backup\20110502-0630/db/revprops/0 : dir
D:\SVN-Backup\20110502-0630/db/revprops/0/0 : file
D:\SVN-Backup\20110502-0630/db/revprops/0/1 : file
D:\SVN-Backup\20110502-0630/db/revprops/0/10 : file
...

恭喜安迪做出的贡献。他解决了这个问题。

A related bug: rt.cpan.org/Public/Bug/Display.html?id=27463, but that's only about files, not directories. What version of Archive::Zip do you have?

我有 perl 5.8.8,它似乎比修复程序更旧。

最佳答案

我找到了CPAN bug 27463 ,如果您有旧版本的 Archive::Zip(<= 1.20,我从 CPAN 可以看出),这可以解释该问题。

正如史努比和我猜测的那样,该错误是由于文件名“0”在用作条件时为假所致。

关于Perl Archive::zip -- 文件未添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5875458/

相关文章:

Perl:将 zip 作为 Base64 编码附件发送会损坏存档

perl - 为什么Perl ENV哈希中缺少某些条目

go - 我是golang的新手,我正在尝试创建一个zip,该zip中必须包含一个文件夹:tosend.zip/archivos/file.png

Mysqldump 导出比 --where 条件中更多的记录

jenkins 存档工件 - 格式是什么?

使用 git-archive 时出现 Git pathspec 错误

perl - 如何在 perl 中使用现有变量打开文件句柄?

perl - 我如何计算我的 perl 代码中每个 sub 的相应行?

Java - 从网站压缩文件?

git - Git 可以将 ZIP 文件视为目录并将 ZIP 内的文件视为 blob 吗?