~ubuntu-branches/ubuntu/trusty/horae/trusty

« back to all changes in this revision

Viewing changes to 0CPAN/Archive-Zip-1.16/examples/updateZip.pl

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Shows how to update a Zip in place using a temp file.
2
 
# $Revision: 1.1 $
3
 
#
4
 
use Archive::Zip qw(:ERROR_CODES);
5
 
use File::Copy();
6
 
 
7
 
my $zipName = shift || die 'must provide a zip name';
8
 
my @fileNames = @ARGV;
9
 
die 'must provide file names' unless scalar(@fileNames);
10
 
 
11
 
# Read the zip
12
 
my $zip = Archive::Zip->new();
13
 
die "can't read $zipName\n" unless $zip->read($zipName) == AZ_OK;
14
 
 
15
 
# Update the zip
16
 
foreach my $file (@fileNames)
17
 
{
18
 
        $zip->removeMember($file);
19
 
        if ( -r $file )
20
 
        {
21
 
                if ( -f $file )
22
 
                {
23
 
                        $zip->addFile($file) or die "Can't add $file to zip!\n";
24
 
                }
25
 
                elsif ( -d $file )
26
 
                {
27
 
                        $zip->addDirectory($file) or die "Can't add $file to zip!\n";
28
 
                }
29
 
                else
30
 
                {
31
 
                        warn "Don't know how to add $file\n";
32
 
                }
33
 
        }
34
 
        else
35
 
        {
36
 
                warn "Can't read $file\n";
37
 
        }
38
 
}
39
 
 
40
 
# Now the zip is updated. Write it back via a temp file.
41
 
 
42
 
exit( $zip->overwrite() );