Skip to content

Commit

Permalink
Fixed: #12493: Can't add new files to archives which contain files named
Browse files Browse the repository at this point in the history
0,1,2,3,4,5,6,7,8,9 with no extension (Files named "0" are not archived)

Also fixed some mistakes
  • Loading branch information
alanhaggai committed Dec 13, 2008
1 parent 679873e commit e27eeda
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/Archive/Zip.pm
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ sub _asZipDirName
File::Spec->splitpath( File::Spec->canonpath($name), $forceDir );
$$volReturn = $volume if ( ref($volReturn) );
my @dirs = map { $_ =~ s{/}{_}g; $_ } File::Spec->splitdir($directories);
if ( @dirs > 0 ) { pop (@dirs) unless $dirs[-1] } # remove empty component
push ( @dirs, defined($file) ? $file : '' );
if ( @dirs > 0 ) { pop (@dirs) unless $dirs[-1] } # remove empty component
push ( @dirs, defined($file) ? $file : '' );
#return wantarray ? @dirs : join ( '/', @dirs );
return join ( '/', @dirs );
}
Expand Down
8 changes: 5 additions & 3 deletions lib/Archive/Zip/Member.pm
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ sub _writeLocalFileHeader {
);

$self->_print($fh, $header) or return _ioError("writing local header");
if ( $self->fileName() ) {

# Check for a valid filename or a filename equal to a literal `0'
if ( $self->fileName() || $self->fileName eq '0' ) {
$self->_print($fh, $self->fileName() )
or return _ioError("writing local header filename");
}
Expand Down Expand Up @@ -915,7 +917,7 @@ sub extractToFileHandle {
my $self = shift;
return _error("encryption unsupported") if $self->isEncrypted();
my $fh = shift;
#_binmode($fh);
_binmode($fh);
my $oldCompression = $self->desiredCompressionMethod(COMPRESSION_STORED);
my $status = $self->rewindData(@_);
$status = $self->_writeData($fh) if $status == AZ_OK;
Expand All @@ -932,7 +934,7 @@ sub _writeToFileHandle {
my $offset = shift;

return _error("no member name given for $self")
unless $self->fileName();
if $self->fileName() eq '';

$self->{'writeLocalHeaderRelativeOffset'} = $offset;
$self->{'wasWritten'} = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/Archive/Zip/NewFileMember.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sub _newFromFileNamed {
$newName = _asZipDirName($fileName) unless defined($newName);
return undef unless ( stat($fileName) && -r _ && !-d _ );
my $self = $class->new(@_);
$self->fileName($newName);
$self->{'fileName'} = $newName;
$self->{'externalFileName'} = $fileName;
$self->{'compressionMethod'} = COMPRESSION_STORED;
my @stat = stat(_);
Expand Down

0 comments on commit e27eeda

Please sign in to comment.