- #print(" Linking $a->{fileName} to $a->{files}[0]->{name}\n");
- if ( @{$a->{files}} && !link($a->{files}[0]->{name}, $a->{fileName}) ) {
- push(@{$a->{errors}}, "Can't link $a->{fileName} to"
- . " $a->{files}[0]->{name}\n");
+ for ( my $i = 0 ; $i < @{$a->{files}} ; $i++ ) {
+ if ( link($a->{files}[$i]->{name}, $a->{fileName}) ) {
+ #print(" Linked $a->{fileName} to $a->{files}[$i]->{name}\n");
+ #
+ # Close the compare files
+ #
+ foreach my $f ( @{$a->{files}} ) {
+ $f->{fh}->close();
+ }
+ return (1, $a->{digest}, -s $a->{fileName}, $a->{errors});
+ }
+ }
+ #
+ # We were unable to link to the pool. Either we're at the
+ # hardlink max, or the pool file got deleted. Recover by
+ # writing the matching file, since we still have an open
+ # handle.
+ #
+ for ( my $i = 0 ; $i < @{$a->{files}} ; $i++ ) {
+ if ( !$a->{files}[$i]->{fh}->rewind() ) {
+ push(@{$a->{errors}},
+ "Unable to rewind $a->{files}[$i]->{name}"
+ . " for copy after link fail\n");
+ next;
+ }
+ $a->{fhOut} = BackupPC::FileZIO->open($a->{fileName},
+ 1, $a->{compress});
+ if ( !defined($a->{fhOut}) ) {
+ push(@{$a->{errors}},
+ "Unable to open $a->{fileName}"
+ . " for writing after link fail\n");
+ }
+ $a->filePartialCopy($a->{files}[$i]->{fh}, $a->{fhOut},
+ $a->{nWrite});
+ $a->{fhOut}->close;
+ last;
+ }
+ #
+ # Close the compare files
+ #
+ foreach my $f ( @{$a->{files}} ) {
+ $f->{fh}->close();