X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FBackupPC%2FXfer%2FRsyncFileIO.pm;h=cc29e293393ded465678b159612b35a157512faa;hb=72b87b178ae8dcc10f1ae0f441d13e30d5f1ecf1;hp=fdc3625b82f63ec06dfdc483e7dba4040a2a9769;hpb=c6cebe03e53dcc49f889cf15ccda5b0fe3acd235;p=BackupPC.git diff --git a/lib/BackupPC/Xfer/RsyncFileIO.pm b/lib/BackupPC/Xfer/RsyncFileIO.pm index fdc3625..cc29e29 100644 --- a/lib/BackupPC/Xfer/RsyncFileIO.pm +++ b/lib/BackupPC/Xfer/RsyncFileIO.pm @@ -8,11 +8,11 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2002 Craig Barratt +# Copyright (C) 2002-2003 Craig Barratt # #======================================================================== # -# Version 2.0.0beta0, released 23 Feb 2003. +# Version 2.1.0_CVS, released 3 Jul 2003. # # See http://backuppc.sourceforge.net. # @@ -135,12 +135,12 @@ sub csumGet return if ( !defined($fio->{fh}) ); if ( $fio->{fh}->read(\$fileData, $blockSize * $num) <= 0 ) { - $fio->log("$fio->{file}{name}: csumGet is at EOF - zero padding\n"); + $fio->log("$fio->{file}{name}: csumGet is at EOF - zero padding"); $fio->{stats}{errorCnt}++; $fileData = pack("c", 0) x ($blockSize * $num); } $fio->{csumDigest}->add($fileData) if ( defined($fio->{csumDigest}) ); - $fio->log(sprintf("%s: getting csum ($num,$csumLen,%d,0x%x)\n", + $fio->log(sprintf("%s: getting csum ($num,$csumLen,%d,0x%x)", $fio->{file}{name}, length($fileData), $fio->{checksumSeed})) @@ -713,13 +713,13 @@ sub fileDeltaRxNext $fio->{stats}{errorCnt}++; return -1; } - if ( $attr->{size} < 10 * 1024 * 1024 ) { + if ( $attr->{size} < 16 * 1024 * 1024 ) { # - # Cache the entire old file if it is less than 10MB + # Cache the entire old file if it is less than 16MB # my $data; $fio->{rxInData} = ""; - while ( $fh->read(\$data, 10 * 1024 * 1024) > 0 ) { + while ( $fh->read(\$data, 16 * 1024 * 1024) > 0 ) { $fio->{rxInData} .= $data; } $fio->log("$attr->{fullPath}: cached all $attr->{size}" @@ -734,6 +734,7 @@ sub fileDeltaRxNext if ( open(F, "+>", "$fio->{outDirSh}RStmp") ) { my $data; my $byteCnt = 0; + binmode(F); while ( $fh->read(\$data, 1024 * 1024) > 0 ) { if ( syswrite(F, $data) != length($data) ) { $fio->log(sprintf("Can't write len=%d to %s", @@ -746,7 +747,7 @@ sub fileDeltaRxNext } $fio->{rxInFd} = *F; $fio->{rxInName} = "$fio->{outDirSh}RStmp"; - seek($fio->{rxInFd}, 0, 0); + sysseek($fio->{rxInFd}, 0, 0); $fio->log("$attr->{fullPath}: copied $byteCnt," . "$attr->{size} bytes to $fio->{rxInName}") if ( $fio->{logLevel} >= 9 ); @@ -760,6 +761,7 @@ sub fileDeltaRxNext $fh->close; } else { if ( open(F, "<", $attr->{fullPath}) ) { + binmode(F); $fio->{rxInFd} = *F; $fio->{rxInName} = $attr->{fullPath}; } else { @@ -774,7 +776,8 @@ sub fileDeltaRxNext . "$lastBlk") if ( $fio->{logLevel} >= 9 ); my $seekPosn = $fio->{rxMatchBlk} * $fio->{rxBlkSize}; - if ( defined($fio->{rxInFd}) && !seek($fio->{rxInFd}, $seekPosn, 0) ) { + if ( defined($fio->{rxInFd}) + && !sysseek($fio->{rxInFd}, $seekPosn, 0) ) { $fio->log("Unable to seek $attr->{rxInName} to $seekPosn"); $fio->{stats}{errorCnt}++; return -1; @@ -803,6 +806,7 @@ sub fileDeltaRxNext $fio->{stats}{errorCnt}++; return -1; } + $seekPosn += $len; } $fio->{rxOutFd}->write(\$data); $fio->{rxDigest}->add($data); @@ -847,19 +851,21 @@ sub fileDeltaRxDone $fio->{rxDigest} = File::RsyncP::Digest->new; $fio->{rxDigest}->add(pack("V", $fio->{checksumSeed})); my $attr = $fio->{rxLocalAttr}; - if ( defined($attr) && defined(my $fh = BackupPC::FileZIO->open( + if ( defined($attr) ) { + if ( defined(my $fh = BackupPC::FileZIO->open( $attr->{fullPath}, 0, $attr->{compress})) ) { - my $data; - while ( $fh->read(\$data, 4 * 65536) > 0 ) { - $fio->{rxDigest}->add($data); - $fio->{rxSize} += length($data); + my $data; + while ( $fh->read(\$data, 4 * 65536) > 0 ) { + $fio->{rxDigest}->add($data); + $fio->{rxSize} += length($data); + } + $fh->close; + } else { + $fio->log("Can't open $attr->{fullPath} for MD4 check ($name)"); + $fio->{stats}{errorCnt}++; } - $fh->close; - } else { - $fio->log("cannot open $attr->{fullPath} for MD4 check"); - $fio->{stats}{errorCnt}++; } $fio->log("$name got exact match") if ( $fio->{logLevel} >= 5 ); @@ -873,8 +879,8 @@ sub fileDeltaRxDone $fio->log("$name got digests $md4Str vs $newStr") } if ( $md4 ne $newDigest ) { - $fio->log("$name md4 doesn't match") - if ( $fio->{logLevel} >= 1 ); + $fio->log("$name: fatal error: md4 doesn't match"); + $fio->{stats}{errorCnt}++; if ( defined($fio->{rxOutFd}) ) { $fio->{rxOutFd}->close; unlink($fio->{rxOutFile}); @@ -964,26 +970,29 @@ sub fileListEltSend || $type == BPC_FTYPE_BLOCKDEV || $type == BPC_FTYPE_SYMLINK ) { my $fh = BackupPC::FileZIO->open($a->{fullPath}, 0, $a->{compress}); - my $str; + my($str, $rdSize); if ( defined($fh) ) { - if ( $fh->read(\$str, $a->{size} + 1) == $a->{size} ) { - if ( $type == BPC_FTYPE_SYMLINK ) { - # - # Reconstruct symbolic link - # - $extraAttribs = { link => $str }; - } elsif ( $str =~ /(\d*),(\d*)/ ) { - # - # Reconstruct char or block special major/minor device num - # - $extraAttribs = { rdev => $1 * 256 + $2 }; - } else { - $fio->log("$name: unexpected special file contents $str"); + $rdSize = $fh->read(\$str, $a->{size} + 1024); + if ( $type == BPC_FTYPE_SYMLINK ) { + # + # Reconstruct symbolic link + # + $extraAttribs = { link => $str }; + if ( $rdSize != $a->{size} ) { + # ERROR + $fio->log("$name: can't read exactly $a->{size} bytes"); $fio->{stats}{errorCnt}++; } + } elsif ( $str =~ /(\d*),(\d*)/ ) { + # + # Reconstruct char or block special major/minor device num + # + # Note: char/block devices have $a->{size} = 0, so we + # can't do an error check on $rdSize. + # + $extraAttribs = { rdev => $1 * 256 + $2 }; } else { - # ERROR - $fio->log("$name: can't read exactly $a->{size} bytes"); + $fio->log("$name: unexpected special file contents $str"); $fio->{stats}{errorCnt}++; } $fh->close;