rewrite home page redirect
[dh-make-perl] / dev / arm / libarchive-zip-perl / libarchive-zip-perl-1.18 / examples / updateZip.pl
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() );