Imported Upstream version 3.3.2
[debian/amanda] / server-src / amcheckdump.pl
index 937f78dec46cf615beb10a30f59a2e10b50663ee..92382e909f96ec73bf16307b8a000f72a8a87741 100644 (file)
@@ -1,5 +1,5 @@
 #! @PERL@
-# Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
+# Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
 # 
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 as published 
@@ -222,7 +222,7 @@ sub find_validation_command {
             "TAR" => [ $Amanda::Constants::GNUTAR, qw(--ignore-zeros -tf -) ],
             "GTAR" => [ $Amanda::Constants::GNUTAR, qw(--ignore-zeros -tf -) ],
             "GNUTAR" => [ $Amanda::Constants::GNUTAR, qw(--ignore-zeros -tf -) ],
-            "SMBCLIENT" => [ $Amanda::Constants::GNUTAR, qw(--ignore-zeros -tf -) ],
+            "SMBCLIENT" => [ $Amanda::Constants::GNUTAR, qw(-tf -) ],
            "PKZIP" => undef,
         );
        if (!exists $validation_programs{$program}) {
@@ -261,7 +261,9 @@ sub main {
     my $all_success = 1;
     my @xfer_errs;
     my %all_filter;
-    my $check_done;
+    my $current_dump;
+    my $recovery_done;
+    my %recovery_params;
 
     my $steps = define_steps
        cb_ref => \$finished_cb,
@@ -340,6 +342,10 @@ sub main {
 
     step check_dumpfile => sub {
        my ($dump) = @_;
+       $current_dump = $dump;
+
+       $recovery_done = 0;
+       %recovery_params = ();
 
        print "Validating image " . $dump->{hostname} . ":" .
            $dump->{diskname} . " dumped " . $dump->{dump_timestamp} . " level ".
@@ -436,8 +442,8 @@ sub main {
                    delete $all_filter{$src};
                    $src->remove();
                    POSIX::close($fd);
-                   if (!%all_filter and $check_done) {
-                       $finished_cb->();
+                   if (!%all_filter and $recovery_done) {
+                       $steps->{'filter_done'}->();
                    }
                } else {
                    $buffer .= $b;
@@ -453,7 +459,7 @@ sub main {
        }
 
        my $xfer = Amanda::Xfer->new([ $xfer_src, @filters, $xfer_dest ]);
-       $xfer->start($steps->{'handle_xmsg'});
+       $xfer->start($steps->{'handle_xmsg'}, 0, $current_dump->{'bytes'});
        $clerk->start_recovery(
            xfer => $xfer,
            recovery_cb => $steps->{'recovery_cb'});
@@ -471,12 +477,17 @@ sub main {
     };
 
     step recovery_cb => sub {
-       my %params = @_;
+       %recovery_params = @_;
+       $recovery_done = 1;
+
+       $steps->{'filter_done'}->() if !%all_filter;
+    };
 
+    step filter_done => sub {
        # distinguish device errors from validation errors
-       if (@{$params{'errors'}}) {
+       if (@{$recovery_params{'errors'}}) {
            print STDERR "While reading from volumes:\n";
-           print STDERR "$_\n" for @{$params{'errors'}};
+           print STDERR "$_\n" for @{$recovery_params{'errors'}};
            return $steps->{'quit'}->("validation aborted");
        }
 
@@ -500,8 +511,8 @@ sub main {
        if ($err) {
            $exit_code = 1;
            print STDERR $err, "\n";
-           return $clerk->quit(finished_cb => $steps->{'quit1'}) if defined $clerk;;
-           return $steps->{'quit1'}->();
+           return $clerk->quit(finished_cb => $finished_cb) if defined $clerk;
+           return $finished_cb->();
        }
 
        if ($all_success) {
@@ -511,16 +522,9 @@ sub main {
            $exit_code = 1;
        }
 
-       return $clerk->quit(finished_cb => $steps->{'quit1'});
+       return $clerk->quit(finished_cb => $finished_cb);
     };
 
-    step quit1 => sub {
-       $check_done = 1;
-
-       if (!%all_filter) {
-           $finished_cb->();
-       }
-    }
 }
 
 main(sub { Amanda::MainLoop::quit(); });