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

Brad Fitzpatrick brad at danga.com
Tue Nov 4 06:08:04 UTC 2008


Just code style.  Rest of project uses style:
     } else {

Braces on same line.

Also, no need for explicit string concat here:

     die "nothing found matching '" . $self->{prefix} . "'.\n";

Just interoplate it.  The ifs are very C-ish too.  You could just do:

die "Nothing found matching $self->{prefix}.\n" if $self->{prefix};
die "Nothing found to restore.  (empty .meta file?)\n";

(also note capitalized sentences in error messages.)


On Mon, Nov 3, 2008 at 1:49 AM, Gavin Carr <gavin at openfusion.com.au> wrote:

> 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 {
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/brackup/attachments/20081103/8d9eca9c/attachment.html 


More information about the brackup mailing list