X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FFileZIO.pm;h=dc6e4807d1861e8dffea0f9eaed42ee3f57e308c;hp=56987cdb4617b09ff140a596ef5ad940aa4ba800;hb=17dcbbebb871212f90b81bb97f8d1feb528bdc43;hpb=74dc9d456332757127d5eda4ce32f29377133fa2 diff --git a/lib/BackupPC/FileZIO.pm b/lib/BackupPC/FileZIO.pm index 56987cd..dc6e480 100644 --- a/lib/BackupPC/FileZIO.pm +++ b/lib/BackupPC/FileZIO.pm @@ -11,7 +11,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2001 Craig Barratt +# Copyright (C) 2001-2003 Craig Barratt # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 2.0.0beta3, released 1 Jun 2003. +# Version 2.1.0, released 20 Jun 2004. # # See http://backuppc.sourceforge.net. # @@ -99,9 +99,10 @@ sub open } else { open(FH, "<", $fileName) || return; } + binmode(FH); $fh = *FH; } - $compLevel = 0 if ( !$CompZlibOK ); + $compLevel = 0 if ( !$CompZlibOK ); my $self = bless { fh => $fh, name => $fileName, @@ -114,6 +115,7 @@ sub open $self->{deflate} = $self->myDeflateInit; } else { $self->{inflate} = $self->myInflateInit; + $self->{inflateStart} = 1; } } return $self; @@ -156,11 +158,42 @@ sub read return $n if ( $n < 0 ); $self->{eof} = 1 if ( $n == 0 ); } + if ( $self->{inflateStart} && $self->{dataIn} ne "" ) { + my $chr = substr($self->{dataIn}, 0, 1); + + $self->{inflateStart} = 0; + if ( $chr eq chr(0xd6) ) { + # + # Flag 0xd6 means this is a compressed file with + # appended md4 block checksums for rsync. Change + # the first byte back to 0x78 and proceed. + # + ##print("Got 0xd6 block: normal\n"); + substr($self->{dataIn}, 0, 1) = chr(0x78); + } elsif ( $chr eq chr(0xb3) ) { + # + # Flag 0xb3 means this is the start of the rsync + # block checksums, so consider this as EOF for + # the compressed file. Also seek the file so + # it is positioned at the 0xb3. + # + sysseek($self->{fh}, -length($self->{dataIn}), 1); + $self->{eof} = 1; + $self->{dataIn} = ""; + ##print("Got 0xb3 block: considering eof\n"); + last; + } else { + # + # normal case: nothing to do + # + } + } my($data, $err) = $self->{inflate}->inflate($self->{dataIn}); $self->{dataOut} .= $data; if ( $err == Z_STREAM_END ) { #print("R"); $self->{inflate} = $self->myInflateInit; + $self->{inflateStart} = 1; } elsif ( $err != Z_OK ) { $$dataRef = ""; return -1; @@ -187,7 +220,8 @@ sub readLine my($self) = @_; my $str; - while ( defined($self->{readLineBuf}) && !@{$self->{readLineBuf}} ) { + $self->{readLineBuf} = [] if ( !defined($self->{readLineBuf}) ); + while ( !@{$self->{readLineBuf}} ) { $self->read(\$str, $CompMaxRead); if ( $str eq "" ) { $str = $self->{readLineFrag}; @@ -214,6 +248,7 @@ sub rewind $self->{dataIn} = ''; $self->{eof} = 0; $self->{inflate} = $self->myInflateInit; + $self->{inflateStart} = 1; return sysseek($self->{fh}, 0, 0); } @@ -246,7 +281,7 @@ sub write my $n = length($$dataRef); return if ( !$self->{write} ); - print($$dataRef) if ( $self->{writeTeeStdout} ); + print(STDERR $$dataRef) if ( $self->{writeTeeStderr} ); return 0 if ( $n == 0 ); if ( !$self->{compress} ) { # @@ -304,12 +339,12 @@ sub name return $self->{name}; } -sub writeTeeStdout +sub writeTeeStderr { my($self, $param) = @_; - $self->{writeTeeStdout} = $param if ( defined($param) ); - return $self->{writeTeeStdout}; + $self->{writeTeeStderr} = $param if ( defined($param) ); + return $self->{writeTeeStderr}; } sub close @@ -353,6 +388,7 @@ sub compressCopy my $fh = BackupPC::FileZIO->open($destFileZ, 1, $compress); my $data; if ( defined($fh) && open(LOG, "<", $srcFile) ) { + binmode(LOG); while ( sysread(LOG, $data, 65536) > 0 ) { $fh->write(\$data); }