Subject: | Archive::Zip corrupts directory only entries from JAR |
When reading a JAR file with some directory-only entries and then
writing it back out using A::Z (without doing anything else), the
archive is corrupt and can't be read according to both the zip and jar
programs. The original JAR can be read by both zip and jar.
If I update the XML file inside the JAR with the zip or jar programs,
it works fine, but if use A::Z I get a corrupt archive.
If I create the equivalent JAR using the zip program instead of the
jar program, there is no problem. (But, I'm not creating the file - it
comes from OpenMake, which uses Ant).
Here is the code that exposes the problem, first create any jar file
called foo.jar with the command 'jar cf foo.jar <files>':
------------------------------------------
#!/usr/bin/perl -w
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use strict;
my $az_foo = Archive::Zip->new('foo.jar');
die 'write error' unless $az_foo->overwriteAs('bar_bad.jar') == AZ_OK;
my ( $meta_inf_member) = $az_foo->removeMember('META-INF/');
die 'write error' unless $az_foo->overwriteAs('bar_good.jar') == AZ_OK;
-------------------------
zip gives a warning on bad_bar.jar: extended local header not found
for META-INF/
jar gives an error on bad_bar.jar:
java.util.zip.ZipException: only DEFLATED entries can have EXT
descriptor
at java.util.zip.ZipInputStream.readLOC(...)
-----------------------------
You may not agree that it is important, but I'm fighting for Perl in
the Java environment and winning, but this was a snag...
-----------------------------
You may also refer to this post on perl monks...
http://perlmonks.org/?node_id=632286
Thanks
Sean Blanton