#
#========================================================================
#
-# Version 2.0.0_CVS, released 18 Jan 2003.
+# Version 2.0.0beta2, released 13 Apr 2003.
#
# See http://backuppc.sourceforge.net.
#
attrib => {},
logHandler => \&logHandler,
stats => {
+ errorCnt => 0,
TotalFileCnt => 0,
TotalFileSize => 0,
ExistFileCnt => 0,
0,
$attr->{compress})) ) {
$fio->log("Can't open $attr->{fullPath} (name=$f->{name})");
+ $fio->{stats}{errorCnt}++;
return -1;
}
if ( $needMD4) {
} else {
delete($fio->{csumDigest});
}
- alarm($fio->{timeout}) if ( defined($fio->{timeout}) );
}
sub csumGet
return if ( !defined($fio->{fh}) );
if ( $fio->{fh}->read(\$fileData, $blockSize * $num) <= 0 ) {
- return;
+ $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}))
- if ( $fio->{logLevel} >= 10 );
+ if ( $fio->{logLevel} >= 9 );
return $fio->{digest}->blockDigest($fileData, $blockSize,
$csumLen, $fio->{checksumSeed});
}
0,
$attr->{compress})) ) {
$fio->log("Can't open $attr->{fullPath} (name=$f->{name})");
+ $fio->{stats}{errorCnt}++;
return;
}
$fio->log("$f->{name}: opened for read") if ( $fio->{logLevel} >= 4 );
- alarm($fio->{timeout}) if ( defined($fio->{timeout}) );
}
sub read
my $poolWrite = BackupPC::PoolWrite->new($fio->{bpc}, $fileName,
length($data), $fio->{xfer}{compress});
$poolWrite->write(\$data);
- $fio->processClose($poolWrite, $fio->{attrib}{$d}->fileName($d),
+ $fio->processClose($poolWrite, $fio->{attrib}{$d}->fileName($dirM),
length($data), 0);
}
delete($fio->{attrib}{$d});
File::Path::mkpath($path, 0, 0777) if ( !-d $path );
return $fio->attribSet($f) if ( -d $path );
$fio->log("Can't create directory $path");
+ $fio->{stats}{errorCnt}++;
return -1;
}
$fio->{rxRemainder} = $remainder; # size of the last block
$fio->{rxMatchBlk} = 0; # current start of match
$fio->{rxMatchNext} = 0; # current next block of match
- my $rxSize = ($cnt - 1) * $size + $remainder;
+ $fio->{rxSize} = 0; # size of received file
+ my $rxSize = $cnt > 0 ? ($cnt - 1) * $size + $remainder : 0;
if ( $fio->{rxFile}{size} != $rxSize ) {
$fio->{rxMatchBlk} = undef; # size different, so no file match
$fio->log("$fio->{rxFile}{name}: size doesn't match"
delete($fio->{rxOutFd});
delete($fio->{rxDigest});
delete($fio->{rxInData});
- alarm($fio->{timeout}) if ( defined($fio->{timeout}) );
}
#
$rxOutFile, $fio->{rxFile}{size},
$fio->{xfer}{compress});
$fio->log("$fio->{rxFile}{name}: opening output file $rxOutFile")
- if ( $fio->{logLevel} >= 10 );
+ if ( $fio->{logLevel} >= 9 );
$fio->{rxOutFile} = $rxOutFile;
$fio->{rxOutFileRel} = $rxOutFileRel;
$fio->{rxDigest} = File::RsyncP::Digest->new;
0,
$attr->{compress})) ) {
$fio->log("Can't open $attr->{fullPath}");
+ $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}"
+ . " bytes")
+ if ( $fio->{logLevel} >= 9 );
} else {
#
# Create and write a temporary output file
#
unlink("$fio->{outDirSh}RStmp")
if ( -f "$fio->{outDirSh}RStmp" );
- if ( open(F, ">+", "$fio->{outDirSh}RStmp") ) {
+ if ( open(F, "+>", "$fio->{outDirSh}RStmp") ) {
my $data;
+ my $byteCnt = 0;
while ( $fh->read(\$data, 1024 * 1024) > 0 ) {
if ( syswrite(F, $data) != length($data) ) {
$fio->log(sprintf("Can't write len=%d to %s",
length($data) , "$fio->{outDirSh}RStmp"));
$fh->close;
+ $fio->{stats}{errorCnt}++;
return -1;
}
+ $byteCnt += length($data);
}
$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 );
} else {
$fio->log("Unable to open $fio->{outDirSh}RStmp");
$fh->close;
+ $fio->{stats}{errorCnt}++;
return -1;
}
}
$fio->{rxInName} = $attr->{fullPath};
} else {
$fio->log("Unable to open $attr->{fullPath}");
+ $fio->{stats}{errorCnt}++;
return -1;
}
}
my $lastBlk = $fio->{rxMatchNext} - 1;
$fio->log("$fio->{rxFile}{name}: writing blocks $fio->{rxMatchBlk}.."
. "$lastBlk")
- if ( $fio->{logLevel} >= 10 );
+ if ( $fio->{logLevel} >= 9 );
my $seekPosn = $fio->{rxMatchBlk} * $fio->{rxBlkSize};
- if ( defined($fio->{rxInFd}) && !seek($fio->{rxInFd}, $seekPosn, 0) ) {
- $fio->log("Unable to seek $attr->{fullPath} to $seekPosn");
+ if ( defined($fio->{rxInFd})
+ && !sysseek($fio->{rxInFd}, $seekPosn, 0) ) {
+ $fio->log("Unable to seek $attr->{rxInName} to $seekPosn");
+ $fio->{stats}{errorCnt}++;
return -1;
}
my $cnt = $fio->{rxMatchNext} - $fio->{rxMatchBlk};
}
if ( defined($fio->{rxInData}) ) {
$data = substr($fio->{rxInData}, $seekPosn, $len);
+ $seekPosn += $len;
} else {
- if ( sysread($fio->{rxInFd}, $data, $len) != $len ) {
- $fio->log("Unable to read $len bytes from"
- . " $fio->{rxInName} "
- . "($i,$thisCnt,$fio->{rxBlkCnt})");
+ my $got = sysread($fio->{rxInFd}, $data, $len);
+ if ( $got != $len ) {
+ my $inFileSize = -s $fio->{rxInName};
+ $fio->log("Unable to read $len bytes from $fio->{rxInName}"
+ . " got=$got, seekPosn=$seekPosn"
+ . " ($i,$thisCnt,$fio->{rxBlkCnt},$inFileSize"
+ . ",$attr->{size})");
+ $fio->{stats}{errorCnt}++;
return -1;
}
+ $seekPosn += $len;
}
$fio->{rxOutFd}->write(\$data);
$fio->{rxDigest}->add($data);
+ $fio->{rxSize} += length($data);
}
$fio->{rxMatchBlk} = undef;
}
#
my $len = length($newData);
$fio->log("$fio->{rxFile}{name}: writing $len bytes new data")
- if ( $fio->{logLevel} >= 10 );
+ if ( $fio->{logLevel} >= 9 );
$fio->{rxOutFd}->write(\$newData);
$fio->{rxDigest}->add($newData);
+ $fio->{rxSize} += length($newData);
}
}
$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);
+ 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 {
- # ERROR
}
$fio->log("$name got exact match")
if ( $fio->{logLevel} >= 5 );
$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});
# One special case is an empty file: if the file size is
# zero we need to open the output file to create it.
#
- if ( $fio->{rxFile}{size} == 0 ) {
+ if ( $fio->{rxSize} == 0 ) {
my $rxOutFileRel = "$fio->{shareM}/"
. $fio->{bpc}->fileNameMangle($name);
my $rxOutFile = $fio->{outDir} . $rxOutFileRel;
$fio->{rxOutFd} = BackupPC::PoolWrite->new($fio->{bpc},
- $rxOutFile, $fio->{rxFile}{size},
+ $rxOutFile, $fio->{rxSize},
$fio->{xfer}{compress});
}
if ( !defined($fio->{rxOutFd}) ) {
. $fio->{bpc}->fileNameMangle($name);
if ( !link($attr->{fullPath}, $rxOutFile) ) {
$fio->log("Unable to link $attr->{fullPath} to $rxOutFile");
+ $fio->{stats}{errorCnt}++;
return -1;
}
#
# Cumulate the stats
#
$fio->{stats}{TotalFileCnt}++;
- $fio->{stats}{TotalFileSize} += $fio->{rxFile}{size};
+ $fio->{stats}{TotalFileSize} += $fio->{rxSize};
$fio->{stats}{ExistFileCnt}++;
- $fio->{stats}{ExistFileSize} += $fio->{rxFile}{size};
+ $fio->{stats}{ExistFileSize} += $fio->{rxSize};
$fio->{stats}{ExistFileCompSize} += -s $rxOutFile;
- return;
+ $fio->{rxFile}{size} = $fio->{rxSize};
+ return $fio->attribSet($fio->{rxFile});
}
}
if ( defined($fio->{rxOutFd}) ) {
my $exist = $fio->processClose($fio->{rxOutFd},
$fio->{rxOutFileRel},
- $fio->{rxFile}{size}, 1);
+ $fio->{rxSize}, 1);
$fio->logFileAction($exist ? "pool" : "create", $fio->{rxFile})
if ( $fio->{logLevel} >= 1 );
+ $fio->{rxFile}{size} = $fio->{rxSize};
+ return $fio->attribSet($fio->{rxFile});
}
delete($fio->{rxDigest});
delete($fio->{rxInData});
#
$extraAttribs = { rdev => $1 * 256 + $2 };
} else {
- # ERROR
- $fio->log("$name: unexpected file contents $str");
+ $fio->log("$name: unexpected special file contents $str");
+ $fio->{stats}{errorCnt}++;
}
} else {
# ERROR
$fio->log("$name: can't read exactly $a->{size} bytes");
+ $fio->{stats}{errorCnt}++;
}
$fh->close;
} else {
# ERROR
$fio->log("$name: can't open");
+ $fio->{stats}{errorCnt}++;
}
}
my $f = {
$fio->{stats}{TotalFileCnt}++;
$fio->{stats}{TotalFileSize} += $a->{size};
}
- alarm($fio->{timeout}) if ( defined($fio->{timeout}) );
}
sub fileListSend
# Flush the attributes if this is the child
#
$fio->attribWrite(undef);
- alarm($fio->{timeout}) if ( defined($fio->{timeout}) );
}
#sub is_tainted