- fixed configure.pl and makeDist.
[BackupPC.git] / lib / BackupPC / Xfer / RsyncFileIO.pm
index cae85c9..820f898 100644 (file)
@@ -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},
@@ -1235,7 +1252,7 @@ sub fileListEltSend
             && ($type == BPC_FTYPE_HARDLINK || $type == BPC_FTYPE_FILE)
             && ($type == BPC_FTYPE_HARDLINK
                     || $fio->{protocol_version} < 27
-                    || $a->{mode} & S_HLINK_TARGET ) ) {
+                    || ($a->{mode} & S_HLINK_TARGET) ) ) {
         #
         # Fill in fake inode information so that the remote rsync
         # can correctly create hardlinks.
@@ -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