FileMember.pm (BackupPC-4.3.2) | : | FileMember.pm (BackupPC-4.4.0) | ||
---|---|---|---|---|
skipping to change at line 35 | skipping to change at line 35 | |||
# This program is distributed in the hope that it will be useful, | # This program is distributed in the hope that it will be useful, | |||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
# GNU General Public License for more details. | # GNU General Public License for more details. | |||
# | # | |||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | |||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
# | # | |||
#======================================================================== | #======================================================================== | |||
# | # | |||
# Version 4.3.2, released 17 Feb 2020. | # Version 4.4.0, released 20 Jun 2020. | |||
# | # | |||
# See http://backuppc.sourceforge.net. | # See http://backuppc.sourceforge.net. | |||
# | # | |||
#======================================================================== | #======================================================================== | |||
package BackupPC::Zip::FileMember; | package BackupPC::Zip::FileMember; | |||
use vars qw( @ISA ); | use vars qw( @ISA ); | |||
@ISA = qw ( Archive::Zip::FileMember ); | @ISA = qw ( Archive::Zip::FileMember ); | |||
BEGIN { use Archive::Zip qw( :CONSTANTS :ERROR_CODES :UTILITY_METHODS ) } | BEGIN { use Archive::Zip qw( :CONSTANTS :ERROR_CODES :UTILITY_METHODS ) } | |||
# Given a file name, set up for eventual writing. | # Given a file name, set up for eventual writing. | |||
sub newFromFileNamed # BackupPC::Zip::FileMember | sub newFromFileNamed # BackupPC::Zip::FileMember | |||
{ | { | |||
my $class = shift; | my $class = shift; | |||
my $fileName = shift; | my $fileName = shift; | |||
my $newName = shift || $fileName; | my $newName = shift || $fileName; | |||
my $size = shift; | my $size = shift; | |||
my $compress = shift; | my $compress = shift; | |||
return undef unless ( stat($fileName) && -r _ && !-d _ ); | return undef unless ( stat($fileName) && -r _ && !-d _ ); | |||
my $self = $class->new(@_); | my $self = $class->new(@_); | |||
$self->fileName($newName); | $self->fileName($newName); | |||
$self->{'externalFileName'} = $fileName; | $self->{'externalFileName'} = $fileName; | |||
$self->{'compressionMethod'} = COMPRESSION_STORED; | $self->{'compressionMethod'} = COMPRESSION_STORED; | |||
$self->{'compressedSize'} = $self->{'uncompressedSize'} = $size; | $self->{'compressedSize'} = $self->{'uncompressedSize'} = $size; | |||
$self->{'fileCompressLevel'} = $compress; | $self->{'fileCompressLevel'} = $compress; | |||
$self->desiredCompressionMethod( ( $self->compressedSize() > 0 ) | $self->desiredCompressionMethod( | |||
? COMPRESSION_DEFLATED | ($self->compressedSize() > 0) | |||
: COMPRESSION_STORED ); | ? COMPRESSION_DEFLATED | |||
$self->isTextFile( -T _ ); | : COMPRESSION_STORED | |||
); | ||||
$self->isTextFile(-T _ ); | ||||
return $self; | return $self; | |||
} | } | |||
sub rewindData # BackupPC::Zip::FileMember | sub rewindData # BackupPC::Zip::FileMember | |||
{ | { | |||
my $self = shift; | my $self = shift; | |||
my $status = $self->SUPER::rewindData(@_); | my $status = $self->SUPER::rewindData(@_); | |||
return $status unless $status == AZ_OK; | return $status unless $status == AZ_OK; | |||
return AZ_IO_ERROR unless $self->fh(); | return AZ_IO_ERROR unless $self->fh(); | |||
$self->fh()->rewind(); | $self->fh()->rewind(); | |||
return AZ_OK; | return AZ_OK; | |||
} | } | |||
sub fh # BackupPC::Zip::FileMember | sub fh # BackupPC::Zip::FileMember | |||
{ | { | |||
my $self = shift; | my $self = shift; | |||
$self->_openFile() if !defined( $self->{'bpcfh'} ); | $self->_openFile() if !defined($self->{'bpcfh'}); | |||
return $self->{'bpcfh'}; | return $self->{'bpcfh'}; | |||
} | } | |||
# opens my file handle from my file name | # opens my file handle from my file name | |||
sub _openFile # BackupPC::Zip::FileMember | sub _openFile # BackupPC::Zip::FileMember | |||
{ | { | |||
my $self = shift; | my $self = shift; | |||
my ( $fh ) = BackupPC::XS::FileZIO::open($self->externalFileName(), 0, | my($fh) = BackupPC::XS::FileZIO::open($self->externalFileName(), 0, $self->{ | |||
$self->{'fileCompressLevel'}); | 'fileCompressLevel'}); | |||
if ( !defined($fh) ) | if ( !defined($fh) ) { | |||
{ | _ioError("Can't open", $self->externalFileName()); | |||
_ioError( "Can't open", $self->externalFileName() ); | ||||
return undef; | return undef; | |||
} | } | |||
$self->{'bpcfh'} = $fh; | $self->{'bpcfh'} = $fh; | |||
return $fh; | return $fh; | |||
} | } | |||
# Closes my file handle | # Closes my file handle | |||
sub _closeFile # BackupPC::Zip::FileMember | sub _closeFile # BackupPC::Zip::FileMember | |||
{ | { | |||
my $self = shift; | my $self = shift; | |||
$self->{'bpcfh'}->close() if ( defined($self->{'bpcfh'}) ); | $self->{'bpcfh'}->close() if ( defined($self->{'bpcfh'}) ); | |||
$self->{'bpcfh'} = undef; | $self->{'bpcfh'} = undef; | |||
} | } | |||
# Make sure I close my file handle | # Make sure I close my file handle | |||
sub endRead # BackupPC::Zip::FileMember | sub endRead # BackupPC::Zip::FileMember | |||
{ | { | |||
my $self = shift; | my $self = shift; | |||
$self->_closeFile(); | $self->_closeFile(); | |||
return $self->SUPER::endRead(@_); | return $self->SUPER::endRead(@_); | |||
} | } | |||
# Return bytes read. Note that first parameter is a ref to a buffer. | # Return bytes read. Note that first parameter is a ref to a buffer. | |||
# my $data; | # my $data; | |||
# my ($bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize ); | # my ($bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize ); | |||
sub _readRawChunk # BackupPC::Zip::FileMember | sub _readRawChunk # BackupPC::Zip::FileMember | |||
{ | { | |||
my ( $self, $dataRef, $chunkSize ) = @_; | my($self, $dataRef, $chunkSize) = @_; | |||
return ( 0, AZ_OK ) unless $chunkSize; | return (0, AZ_OK) unless $chunkSize; | |||
my $bytesRead = $self->fh()->read( $dataRef, $chunkSize ) | my $bytesRead = $self->fh()->read($dataRef, $chunkSize) | |||
or return ( 0, _ioError("reading data") ); | or return (0, _ioError("reading data")); | |||
return ( $bytesRead, AZ_OK ); | return ($bytesRead, AZ_OK); | |||
} | } | |||
sub extractToFileNamed # BackupPC::Zip::FileMember | sub extractToFileNamed # BackupPC::Zip::FileMember | |||
{ | { | |||
die("BackupPC::Zip::FileMember::extractToFileNamed not supported\n"); | die("BackupPC::Zip::FileMember::extractToFileNamed not supported\n"); | |||
} | } | |||
# | # | |||
# There is a bug in Archive::Zip 1.30 that causes BackupPC_zipCreate | # There is a bug in Archive::Zip 1.30 that causes BackupPC_zipCreate | |||
# to fail when compression is on and it is writing to an unseekable | # to fail when compression is on and it is writing to an unseekable | |||
# output file (eg: pipe or socket); see: | # output file (eg: pipe or socket); see: | |||
# | # | |||
# https://rt.cpan.org/Public/Bug/Display.html?id=54827 | # https://rt.cpan.org/Public/Bug/Display.html?id=54827 | |||
End of changes. 14 change blocks. | ||||
24 lines changed or deleted | 26 lines changed or added |