From f244e2aa7f1fd373173b87f58a627c07cf01af19 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 7 Dec 2020 16:10:07 +0100 Subject: [PATCH] api: content/backup: handle deletion of notes 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.39.2