in reply to Re: Problem with creating a zip: void file
in thread Problem with creating a zip: void file


First of all, thanks for your reply :)

I have added print statement and it outputs the same of "cat" command:
my_script.pl /home/user/a/a.txt /home/user/b/b.txt /home/user/c/c.txt
and my zip file is still void :(

But if I put the three txt files (a.txt, b.txt, c.txt) in the same directory of perl script, then the script works as aspected and my zip file contains the three files

Replies are listed 'Best First'.
Re^3: Problem with creating a zip: void file
by kennethk (Abbot) on Feb 05, 2010 at 22:19 UTC
    The only suggestion I can make is that in reformatting your information for posting, you have somehow removed your bug. Specifically, running the script:

    #! /usr/bin/perl use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new(); open (FILE_LIST, '/home/user/d/file_list.txt') or die "File list open + fail: $!"; while (<FILE_LIST>) { chomp; my $member = $zip->addFile($_); print "Add error" unless ($member); } close FILE_LIST; unless ($zip->writeToFileNamed('/home/user/d/backup.zip') == AZ_OK) { die "write error";}

    from multiple directories yielded success for me, with input file:

    /home/user/a/a.txt /home/user/b/b.txt /home/user/c/c.txt

    and where success was measured by the results of the script:

    #! /usr/bin/perl use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new('backup.zip'); print $zip->memberNames();

    where the only scrubbing I performed was changing user name. The only other suggestion I can make is that a review of the add_file method in Archive::Zip includes the admonition:

    NOTE that you shouldn't (generally) use absolute path names in zip member names, as this will cause problems with some zip tools as well as introduce a security hole and make the zip harder to use.
      My script has probably always worked but my graphical zip tool, Xarchiver (xarchiver.xfce.org), doesn't show its content :(

      This is instead the output of console tool unzip:
      unzip -l backup.zip Archive: backup.zip Length Date Time Name --------- ---------- ----- ---- 1 2010-02-05 22:29 /home/user/a/a.txt 1 2010-02-05 22:28 /home/user/b/b.txt 1 2010-02-05 22:29 /home/user/c/c.txt --------- ------- 3 3 files
      and your test script:
      #! /usr/bin/perl use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new('/home/user/d/backup.zip'); print $zip->memberNames();
      prints my backup.zip content as well:
      perl test_script.pl /home/user/a/a.txt/home/user/b/b.txt/home/user/c/c.txt
      Thank you very much for your answers :)