backup subcommand works, with index, and without index
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Mon, 16 Dec 2013 14:31:18 +0100
changeset 6 452350b85682
parent 5 5488aa9488af
child 7 29ca93ca12e0
backup subcommand works, with index, and without index
bin/amdumpext
--- a/bin/amdumpext	Mon Dec 16 11:13:32 2013 +0100
+++ b/bin/amdumpext	Mon Dec 16 14:31:18 2013 +0100
@@ -17,6 +17,7 @@
 use 5.010;
 use strict;
 use warnings;
+use Carp;
 use Pod::Usage;
 use Getopt::Long;
 use File::Basename;
@@ -242,12 +243,20 @@
                     die "Can't exec `restore -tvf -`: $!";
                 };
 
+		# the restore may close it's input, we'll get
+		# a SIG{PIPE} because of this
+		local $SIG{PIPE} = sub { 
+		    close $restore;
+		    $restore = undef;
+		    $SIG{PIPE} = 'default';
+		};
+
                 local $/ = \(my $x = 64 * 1024);
                 while (<STDIN>) {
                     print $_;
-                    print $restore $_;
+                    print $restore $_ if $restore;
                 }
-		close($restore);
+		close($restore) if $restore;
                 exit 0;
             };
 	    
@@ -289,7 +298,7 @@
             exit 0;
         };
         exec @dump;
-        die "Can't exec `@dump`: $!\n";
+        die "Can't exec `@dump': $!\n";
     }
     waitpid($pid, 0);
     exit $?;
@@ -330,7 +339,8 @@
     # restore to use a \0 separated output format
 
     select +shift;
-    local $/ = "\n";	# make sure to have it line separated!
+    die 'IFS is not as expected!' if $/ ne "\n";
+
 
     my $buffer = undef;
     my $type   = undef;
@@ -343,7 +353,7 @@
         if (1 .. defined && /\Adir\s+\d+\s+(.*)\Z/) {
             $buffer = '';
             $type   = 'dir';
-	    die "Unexpected end of input\n" if not defined;
+	    die "Unexpected end of input while reading from restore -tvf\n" if not defined;
             next;
         }