Subject: | 1.15_02 unnecessarily creates file handles for directory members |
Distribution name and version: Archive-Zip-1.15_02
perl -v: v5.8.5 built for i386-linux-thread-multi
uname -a: Linux ingrid.hq.netapp.com 2.6.9-1.667 #1 Tue Nov 2 14:41:25 EST 2004 i686 i686 i386 GNU/Linux
When a zip archive is read by readFromFileHandle, a new file
handle is created for every directory member.
Here's the flow:
Archive::Zip::Archive::readFromFileHandle
contains
$status = $newMember->endRead();
return $status if $status != AZ_OK;
$newMember->_becomeDirectoryIfNecessary();
endRead() resolves to
Archive::Zip::FileMember::endRead
This method contains
undef $self->{'fh'}; # _closeFile();
thus dropping the reference to the file handle.
readFromFileHandle then executes
$newMember->_becomeDirectoryIfNecessary();
_becomeDirectoryIfNecessary() resolves to
Archive::Zip::Member::_becomeDirectoryIfNecessary
This method contains
$self->_become(DIRECTORYMEMBERCLASS)
if $self->isDirectory();
For a directory member, _become() is called. This resolves to
Archive::Zip::ZipFileMember::_become
This method contains
if ( _isSeekable( $self->fh() ) )
The fh() call resolves to
Archive::Zip::FileMember::fh
This method contains
$self->_openFile()
if !defined( $self->{'fh'} ) || !$self->{'fh'}->opened();
Since $self->{'fh'} is not defined, having been undefined back
in endRead(), _openFile() is called. This resolves to
Archive::Zip::FileMember::_openFile
This method contains
my ( $status, $fh ) = _newFileHandle( $self->externalFileName(), 'r' );
which creates a new file handle.
For my application, this is not just an inefficiency.
I'm passing my own file handle object to readFromFileHandle
instead of the usual IO::File object. I want my file handle
object used for all I/O, not replaced by an IO::File object.
I used the attached patch to get around the problem, but there
may well be a better solution.
Message body not shown because it is not plain text.