From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] applied: [PATCH storage 1/2] api: content/backup: handle deletion of notes
Date: Mon, 7 Dec 2020 16:16:03 +0100 [thread overview]
Message-ID: <20201207151604.2207598-1-t.lamprecht@proxmox.com> (raw)
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 | 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
next reply other threads:[~2020-12-07 15:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-07 15:16 Thomas Lamprecht [this message]
2020-12-07 15:16 ` [pve-devel] applied: [PATCH storage 2/2] nfs and cifs: implement backup notes helper Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201207151604.2207598-1-t.lamprecht@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox