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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2020-12-07 16:10:07 +01:00
parent 20471dfd95
commit f244e2aa7f
2 changed files with 7 additions and 4 deletions

View File

@ -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;

View File

@ -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;
}