]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
vzdump: new: add add_error helper
authorFabian Ebner <f.ebner@proxmox.com>
Tue, 19 Apr 2022 08:45:21 +0000 (10:45 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 27 Apr 2022 08:36:19 +0000 (10:36 +0200)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/VZDump.pm

index f34a5969b630c0ea03bd32a7aef2458ed16ac19e..bdf270f71744df85da7959be12c622d143f15c9c 100644 (file)
@@ -505,19 +505,21 @@ sub new {
     PVE::Cluster::cfs_update(); # Pick up possible changes made by the hook script.
 
     my $errors = '';
+    my $add_error = sub {
+       my ($error) = @_;
+       $errors .= "\n" if $errors;
+       chomp($error);
+       $errors .= $error;
+    };
 
     if ($opts->{storage}) {
        my $storage_cfg = PVE::Storage::config();
        eval { PVE::Storage::activate_storage($storage_cfg, $opts->{storage}) };
-       if (my $err = $@) {
-           chomp($err);
-           $errors .= "could not activate storage '$opts->{storage}': $err";
-       }
+       $add_error->("could not activate storage '$opts->{storage}': $@") if $@;
 
        my $info = eval { storage_info ($opts->{storage}) };
        if (my $err = $@) {
-           chomp($err);
-           $errors .= "could not get storage information for '$opts->{storage}': $err";
+           $add_error->("could not get storage information for '$opts->{storage}': $err");
        } else {
            $opts->{dumpdir} = $info->{dumpdir};
            $opts->{scfg} = $info->{scfg};
@@ -525,7 +527,7 @@ sub new {
            $opts->{'prune-backups'} //= $info->{'prune-backups'};
        }
     } elsif ($opts->{dumpdir}) {
-       $errors .= "dumpdir '$opts->{dumpdir}' does not exist"
+       $add_error->("dumpdir '$opts->{dumpdir}' does not exist")
            if ! -d $opts->{dumpdir};
     } else {
        die "internal error";
@@ -537,8 +539,7 @@ sub new {
     $opts->{remove} = 0 if $opts->{'prune-backups'}->{'keep-all'};
 
     if ($opts->{tmpdir} && ! -d $opts->{tmpdir}) {
-       $errors .= "\n" if $errors;
-       $errors .= "tmpdir '$opts->{tmpdir}' does not exist";
+       $add_error->("tmpdir '$opts->{tmpdir}' does not exist");
     }
 
     if ($errors) {