X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FXfer%2FRsyncFileIO.pm;h=820f898192d7e17240b8e5ffd1e1f403d378c1f2;hp=c0cf21bbfec2e56675566136838c5a91acee73bb;hb=5b3e6091d542c2e7445d5dd511cdf6e20aec8b8d;hpb=17dcbbebb871212f90b81bb97f8d1feb528bdc43 diff --git a/lib/BackupPC/Xfer/RsyncFileIO.pm b/lib/BackupPC/Xfer/RsyncFileIO.pm index c0cf21b..820f898 100644 --- a/lib/BackupPC/Xfer/RsyncFileIO.pm +++ b/lib/BackupPC/Xfer/RsyncFileIO.pm @@ -12,7 +12,7 @@ # #======================================================================== # -# Version 2.1.0, released 20 Jun 2004. +# Version 3.0.0alpha, released 23 Jan 2006. # # See http://backuppc.sourceforge.net. # @@ -22,6 +22,7 @@ package BackupPC::Xfer::RsyncFileIO; use strict; use File::Path; +use Encode qw/from_to/; use BackupPC::Attrib qw(:all); use BackupPC::View; use BackupPC::Xfer::RsyncDigest qw(:all); @@ -735,23 +736,23 @@ sub logFileAction my $owner = "$f->{uid}/$f->{gid}"; my $type = (("", "p", "c", "", "d", "", "b", "", "", "", "l", "", "s")) [($f->{mode} & S_IFMT) >> 12]; - my $link; + my $name = $f->{name}; if ( ($f->{mode} & S_IFMT) == S_IFLNK ) { - $link = " -> $f->{link}"; - } if ( ($f->{mode} & S_IFMT) == S_IFREG + $name .= " -> $f->{link}"; + } elsif ( ($f->{mode} & S_IFMT) == S_IFREG && defined($f->{hlink}) && !$f->{hlink_self} ) { - $link = " -> $f->{hlink}"; + $name .= " -> $f->{hlink}"; } + $name =~ s/\n/\\n/g; - $fio->log(sprintf(" %-6s %1s%4o %9s %11.0f %s%s", + $fio->log(sprintf(" %-6s %1s%4o %9s %11.0f %s", $action, $type, $f->{mode} & 07777, $owner, $f->{size}, - $f->{name}, - $link)); + $name)); } # @@ -1145,22 +1146,38 @@ sub fileDeltaRxDone # my $rxOutFile = $fio->{outDirSh} . $fio->{bpc}->fileNameMangle($name); - if ( !link($attr->{fullPath}, $rxOutFile) ) { - $fio->log("Unable to link $attr->{fullPath} to $rxOutFile"); - $fio->{stats}{errorCnt}++; - $ret = -1; - } else { - # - # Cumulate the stats - # - $fio->{stats}{TotalFileCnt}++; - $fio->{stats}{TotalFileSize} += $fio->{rxSize}; - $fio->{stats}{ExistFileCnt}++; - $fio->{stats}{ExistFileSize} += $fio->{rxSize}; - $fio->{stats}{ExistFileCompSize} += -s $rxOutFile; - $fio->{rxFile}{size} = $fio->{rxSize}; - $ret = $fio->attribSet($fio->{rxFile}); - } + my($exists, $digest, $origSize, $outSize, $errs) + = BackupPC::PoolWrite::LinkOrCopy( + $fio->{bpc}, + $attr->{fullPath}, + $attr->{compress}, + $rxOutFile, + $fio->{xfer}{compress}); + # + # Cumulate the stats + # + $fio->{stats}{TotalFileCnt}++; + $fio->{stats}{TotalFileSize} += $fio->{rxSize}; + $fio->{stats}{ExistFileCnt}++; + $fio->{stats}{ExistFileSize} += $fio->{rxSize}; + $fio->{stats}{ExistFileCompSize} += -s $rxOutFile; + $fio->{rxFile}{size} = $fio->{rxSize}; + $ret = $fio->attribSet($fio->{rxFile}); + $fio->log(@$errs) if ( defined($errs) && @$errs ); + + if ( !$exists && $outSize > 0 ) { + # + # the hard link failed, most likely because the target + # file has too many links. We have copied the file + # instead, so add this to the new file list. + # + my $rxOutFileRel = "$fio->{shareM}/" + . $fio->{bpc}->fileNameMangle($name); + $rxOutFileRel =~ s{^/+}{}; + my $fh = $fio->{newFilesFH}; + print($fh "$digest $origSize $rxOutFileRel\n") + if ( defined($fh) ); + } } } else { my $exist = $fio->processClose($fio->{rxOutFd}, @@ -1285,10 +1302,16 @@ sub fileListEltSend size => $a->{size}, %$extraAttribs, }; + my $logName = $f->{name}; + from_to($f->{name}, "utf8", $fio->{clientCharset}) + if ( $fio->{clientCharset} ne "" ); $fList->encode($f); - $f->{name} = "$fio->{xfer}{pathHdrDest}/$f->{name}"; - $f->{name} =~ s{//+}{/}g; + + $logName = "$fio->{xfer}{pathHdrDest}/$f->{name}"; + $logName =~ s{//+}{/}g; + $f->{name} = $logName; $fio->logFileAction("restore", $f) if ( $fio->{logLevel} >= 1 ); + &$outputFunc($fList->encodeData); # # Cumulate stats