]> git.proxmox.com Git - pve-storage.git/commitdiff
api: content/backup: handle deletion of notes
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 7 Dec 2020 15:10:07 +0000 (16:10 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 7 Dec 2020 15:10:09 +0000 (16:10 +0100)
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>
PVE/API2/Storage/Content.pm
PVE/Storage/DirPlugin.pm

index 349231df9fc71d1b6e4eafb1259dfdb5fee4e124..c391b357e9aa53262665b3ed6259339152881c01 100644 (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;
index 7bb85e824194f02b3bde600df8ac01eb806d8189..2267f117c963e3e7a05a00f4a563149c5aca8163 100644 (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;
 }