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 0769069CFC for ; Mon, 7 Dec 2020 16:16:43 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id F269827598 for ; Mon, 7 Dec 2020 16:16:12 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 7A69B27582 for ; Mon, 7 Dec 2020 16:16:09 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3E96F44E64 for ; Mon, 7 Dec 2020 16:16:09 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Date: Mon, 7 Dec 2020 16:16:03 +0100 Message-Id: <20201207151604.2207598-1-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.070 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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] applied: [PATCH storage 1/2] api: content/backup: handle deletion of notes 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: Mon, 07 Dec 2020 15:16:43 -0000 Previous to this we did not called the plugins update_volume_notes at all in the case where a user delted the textarea, which results to passing a falsy value (''). Also adapt the currently sole implementation to delete the notes field in the undef or '' value case. This can be done safely, as we default to returning an empty string if no notes file exists. Signed-off-by: Thomas Lamprecht --- PVE/API2/Storage/Content.pm | 4 ++-- PVE/Storage/DirPlugin.pm | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm index 349231d..c391b35 100644 --- a/PVE/API2/Storage/Content.pm +++ b/PVE/API2/Storage/Content.pm @@ -370,8 +370,8 @@ __PACKAGE__->register_method ({ PVE::Storage::check_volume_access($rpcenv, $authuser, $cfg, undef, $volid); - if (my $notes = $param->{notes}) { - PVE::Storage::update_volume_notes($cfg, $volid, $notes); + if (exists $param->{notes}) { + PVE::Storage::update_volume_notes($cfg, $volid, $param->{notes}); } return undef; diff --git a/PVE/Storage/DirPlugin.pm b/PVE/Storage/DirPlugin.pm index 7bb85e8..2267f11 100644 --- a/PVE/Storage/DirPlugin.pm +++ b/PVE/Storage/DirPlugin.pm @@ -107,8 +107,11 @@ sub update_volume_notes { my $path = $class->filesystem_path($scfg, $volname); $path .= $class->SUPER::NOTES_EXT; - PVE::Tools::file_set_contents($path, $notes); - + if (defined($notes) && $notes ne '') { + PVE::Tools::file_set_contents($path, $notes); + } else { + unlink $path or die "could not delete notes - $!\n"; + } return; } -- 2.20.1