X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FFileZIO.pm;h=0b2387334dbc2b7a150be3058604deeaf83fd24b;hp=637a39d476bbec827013ec87ffaa2d04af11f39b;hb=5b3e6091d542c2e7445d5dd511cdf6e20aec8b8d;hpb=0697368bbcef14908cd4684cf07744dc840464de diff --git a/lib/BackupPC/FileZIO.pm b/lib/BackupPC/FileZIO.pm index 637a39d..0b23873 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.0_CVS, released 18 Jan 2003. +# Version 3.0.0alpha, released 23 Jan 2006. # # 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,6 +281,7 @@ sub write my $n = length($$dataRef); return if ( !$self->{write} ); + print(STDERR $$dataRef) if ( $self->{writeTeeStderr} ); return 0 if ( $n == 0 ); if ( !$self->{compress} ) { # @@ -303,6 +339,14 @@ sub name return $self->{name}; } +sub writeTeeStderr +{ + my($self, $param) = @_; + + $self->{writeTeeStderr} = $param if ( defined($param) ); + return $self->{writeTeeStderr}; +} + sub close { my($self) = @_; @@ -344,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); }