From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id A6D161FF16E for ; Mon, 29 Jul 2024 16:30:04 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 149C61EB32; Mon, 29 Jul 2024 16:30:04 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Mon, 29 Jul 2024 16:29:56 +0200 Message-Id: <20240729142956.58257-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.060 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 Subject: [pve-devel] [PATCH storage] api: upload: correctly test for result of unlink 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" It's not enough to check whether $! is set. From "perldoc perlvar": > Many system or library calls set "errno" if they fail, to > indicate the cause of failure. They usually do not set "errno" > to zero if they succeed and may set "errno" to a non-zero value > on success. This means "errno", hence $!, is meaningful only > *immediately* after a failure: To protect against potential issues, check the return value of unlink and only check $! if it failed. Signed-off-by: Fiona Ebner --- src/PVE/API2/Storage/Status.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm index dc6cc69..f86e5d3 100644 --- a/src/PVE/API2/Storage/Status.pm +++ b/src/PVE/API2/Storage/Status.pm @@ -461,7 +461,7 @@ __PACKAGE__->register_method ({ # best effort to match apl_download behaviour chmod 0644, $tmpfilename; - my $err_cleanup = sub { unlink $dest; die "cleanup failed: $!\n" if $! && $! != ENOENT }; + my $err_cleanup = sub { unlink $dest or $! == ENOENT or die "cleanup failed: $!\n" }; my $cmd; if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) { @@ -513,9 +513,8 @@ __PACKAGE__->register_method ({ }; if (my $err = $@) { # unlinks only the temporary file from the http server - unlink $tmpfilename; - warn "unable to clean up temporory file '$tmpfilename' - $!\n" - if $! && $! != ENOENT; + unlink $tmpfilename or $! == ENOENT + or warn "unable to clean up temporory file '$tmpfilename' - $!\n"; die $err; } @@ -526,8 +525,9 @@ __PACKAGE__->register_method ({ eval { run_command($cmd, errmsg => 'import failed'); }; - unlink $tmpfilename; # the temporary file got only uploaded locally, no need to rm remote - warn "unable to clean up temporary file '$tmpfilename' - $!\n" if $! && $! != ENOENT; + # the temporary file got only uploaded locally, no need to rm remote + unlink $tmpfilename or $! == ENOENT + or warn "unable to clean up temporary file '$tmpfilename' - $!\n"; if (my $err = $@) { eval { $err_cleanup->() }; -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel