X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FXfer%2FRsyncDigest.pm;h=b88168118765f9bfcb236c0a9fa9e6d330e8a910;hp=07d5a10f2918749832adc6785e21b03898db2eb7;hb=b81d2da5e16975674f011e4833337ac0fa24e0ea;hpb=1a2fa2c2a1e0db12dc788216d9f3ba73301a131f diff --git a/lib/BackupPC/Xfer/RsyncDigest.pm b/lib/BackupPC/Xfer/RsyncDigest.pm index 07d5a10..b881681 100644 --- a/lib/BackupPC/Xfer/RsyncDigest.pm +++ b/lib/BackupPC/Xfer/RsyncDigest.pm @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 2.1.0beta2, released 9 May 2004. +# Version 3.0.0beta2, released 11 Nov 2006. # # See http://backuppc.sourceforge.net. # @@ -42,6 +42,7 @@ use BackupPC::FileZIO; use vars qw( $RsyncLibOK ); use Carp; +use Fcntl; require Exporter; use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS ); @@ -100,7 +101,7 @@ sub fileDigestIsCached my($class, $file) = @_; my $data; - open(my $fh, "<", $file) || return -1; + sysopen(my $fh, $file, O_RDONLY) || return -1; binmode($fh); return -2 if ( sysread($fh, $data, 1) != 1 ); close($fh); @@ -113,6 +114,7 @@ sub fileDigestIsCached # Empty files don't get cached checksums. # # If verify is set then existing cached checksums are checked. +# If verify == 2 then only a verify is done; no fixes are applied. # # Returns 0 on success. Returns 1 on good verify and 2 on bad verify. # Returns a variety of negative values on error. @@ -142,15 +144,17 @@ sub digestAdd return -102 if ( !defined(my $fh = BackupPC::FileZIO->open($file, 0, 1)) ); + my $fileSize; while ( 1 ) { $fh->read(\$data, $nBlks * $blockSize); + $fileSize += length($data); last if ( $data eq "" ); $blockDigest .= $digest->blockDigest($data, $blockSize, 16, $checksumSeed); $digest->add($data); } $fileDigest = $digest->digest2; - my $eofPosn = tell($fh->{fh}); + my $eofPosn = sysseek($fh->{fh}, 0, 1); $fh->close; my $rsyncData = $blockDigest . $fileDigest; my $metaData = pack("VVVV", $blockSize, @@ -164,7 +168,7 @@ sub digestAdd # length($metaData), # $file, # $eofPosn); - open(my $fh2, "+<", $file) || return -103; + sysopen(my $fh2, $file, O_RDWR) || return -103; binmode($fh2); return -104 if ( sysread($fh2, $data, 1) != 1 ); if ( $data ne chr(0x78) && $data ne chr(0xd6) ) { @@ -187,9 +191,13 @@ sub digestAdd # # Checksums don't agree - fall through so we rewrite the data # - &$Log("digestAdd: $file verify failed; redoing checksums"); + &$Log(sprintf("digestAdd: %s verify failed; redoing checksums; len = %d,%d; eofPosn = %d, fileSize = %d", + $file, length($data2), length($data3), $eofPosn, $fileSize)); + #&$Log(sprintf("dataNew = %s", unpack("H*", $data2))); + #&$Log(sprintf("dataFile = %s", unpack("H*", $data3))); return -109 if ( sysseek($fh2, $eofPosn, 0) != $eofPosn ); $retValue = 2; + return $retValue if ( $verify == 2 ); } return -110 if ( syswrite($fh2, $data2) != length($data2) ); if ( $verify ) { @@ -199,14 +207,15 @@ sub digestAdd # match our expected length. # return -111 if ( !defined(sysseek($fh2, 0, 2)) ); - if ( tell($fh2) != $eofPosn + length($data2) ) { + if ( sysseek($fh2, 0, 1) != $eofPosn + length($data2) ) { if ( !truncate($fh2, $eofPosn + length($data2)) ) { &$Log(sprintf("digestAdd: $file truncate from %d to %d failed", - tell($fh2), $eofPosn + length($data2))); + sysseek($fh2, 0, 1), $eofPosn + length($data2))); return -112; } else { - &$Log(sprintf("digestAdd: $file truncated from %d to %d", - tell($fh2), $eofPosn + length($data2))); + &$Log(sprintf("digestAdd: %s truncated from %d to %d", + $file, + sysseek($fh2, 0, 1), $eofPosn + length($data2))); } } }