From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 45668DA35 for ; Tue, 19 Apr 2022 10:45:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3BD7225860 for ; Tue, 19 Apr 2022 10:45:27 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B50D225857 for ; Tue, 19 Apr 2022 10:45:26 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8D34442162 for ; Tue, 19 Apr 2022 10:45:26 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 19 Apr 2022 10:45:21 +0200 Message-Id: <20220419084522.17916-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.099 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH manager 1/2] vzdump: new: add add_error helper X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Apr 2022 08:45:57 -0000 Signed-off-by: Fabian Ebner --- PVE/VZDump.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm index f34a5969..bdf270f7 100644 --- a/PVE/VZDump.pm +++ b/PVE/VZDump.pm @@ -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) { -- 2.30.2