[PATCH] Make brackup-restore report errors if nothing restored

Gavin Carr gavin at openfusion.com.au
Mon Nov 3 09:49:45 UTC 2008


Here's a proposed patch to make brackup-restore complain if nothing is
found to restore (probably most useful with --just, but works with --all
as well. 

Any thoughts/comments/objections before I commit?

Cheers,
Gavin


=== modified file 'lib/Brackup/Restore.pm'
--- lib/Brackup/Restore.pm      2008-07-29 21:29:25 +0000
+++ lib/Brackup/Restore.pm      2008-11-01 01:48:17 +0000
@@ -71,6 +71,7 @@
     $self->{_target} = $target;
     $self->{_meta}   = $meta;
 
+    my $restore_count = 0;
     while (my $it = $parser->readline) {
         my $type = $it->{Type} || "f";
         die "Unknown filetype: type=$type, file: $it->{Path}" unless $type =~ /^[ldfp]$/;
@@ -88,6 +89,7 @@
             }
         }
 
+        $restore_count++;
         my $full = $self->{to} . "/" . $it->{Path};
 
         # restore default modes from header
@@ -101,10 +103,21 @@
         $self->_restore_file     ($full, $it) if $type eq "f";
     }
 
-    warn " * fixing stat info\n" if $self->{verbose};
-    $self->_exec_statinfo_updates;
-    warn " * done\n" if $self->{verbose};
-    return 1;
+    if ($restore_count) {
+        warn " * fixing stat info\n" if $self->{verbose};
+        $self->_exec_statinfo_updates;
+        warn " * done\n" if $self->{verbose};
+        return 1;
+    }
+
+    else {
+        if ($self->{prefix}) {
+            die "nothing found matching '" . $self->{prefix} . "'.\n";
+        }
+        else {
+            die "nothing found to restore.\n";
+        }
+    }
 }
 
 sub _output_temp_filename {



More information about the brackup mailing list