* [pve-devel] [PATCH storage] prune {validate, mark}: preserve input parameter
@ 2021-09-09 9:58 Fabian Ebner
2021-09-09 16:09 ` [pve-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Fabian Ebner @ 2021-09-09 9:58 UTC (permalink / raw)
To: pve-devel
While the current way to detect settings like { 'keep-last' => 0 } is
concise, it's also wrong, because but the delete operation is visible
to the caller. This resulted in e.g.
# $hash is { 'keep-all' => 1 }
my $s = print_property_string($hash, 'prune-backups');
# $hash is now {}, $s is 'keep-all=1'
because validation is called in print_property_string. The same issue
is present when calling prune_mark_backup_group.
Because validation complains when keep-all and something else is set,
this shouldn't have caused any real issues, besides vzdump with
keep-all=1 wrongly taking the removal path, but without any settings,
so not removing anything:
INFO: prune older backups with retention:
INFO: pruned 0 backup(s)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
PVE/Storage.pm | 5 ++---
PVE/Storage/Plugin.pm | 7 ++++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index c04b5a2..7b319fe 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1666,10 +1666,9 @@ my $prune_mark = sub {
sub prune_mark_backup_group {
my ($backup_group, $keep) = @_;
- my $keep_all = delete $keep->{'keep-all'};
+ my @positive_opts = grep { $_ ne 'keep-all' && $keep->{$_} > 0 } keys $keep->%*;
- if ($keep_all || !scalar(grep {$_ > 0} values %{$keep})) {
- $keep = { 'keep-all' => 1 } if $keep_all;
+ if ($keep->{'keep-all'} || scalar(@positive_opts) == 0) {
foreach my $prune_entry (@{$backup_group}) {
$prune_entry->{mark} = 'keep';
}
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index b1865cb..870091d 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -93,11 +93,12 @@ PVE::JSONSchema::register_format('prune-backups', $prune_backups_format, \&valid
sub validate_prune_backups {
my ($prune_backups) = @_;
- my $keep_all = delete $prune_backups->{'keep-all'};
+ my @positive_opts =
+ grep { $_ ne 'keep-all' && $prune_backups->{$_} > 0 } keys $prune_backups->%*;
- if (!scalar(grep {$_ > 0} values %{$prune_backups})) {
+ if (scalar(@positive_opts) == 0) {
$prune_backups = { 'keep-all' => 1 };
- } elsif ($keep_all) {
+ } elsif ($prune_backups->{'keep-all'}) {
die "keep-all cannot be set together with other options.\n";
}
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pve-devel] applied: [PATCH storage] prune {validate, mark}: preserve input parameter
2021-09-09 9:58 [pve-devel] [PATCH storage] prune {validate, mark}: preserve input parameter Fabian Ebner
@ 2021-09-09 16:09 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2021-09-09 16:09 UTC (permalink / raw)
To: Proxmox VE development discussion, Fabian Ebner
On 09.09.21 11:58, Fabian Ebner wrote:
> While the current way to detect settings like { 'keep-last' => 0 } is
> concise, it's also wrong, because but the delete operation is visible
> to the caller. This resulted in e.g.
> # $hash is { 'keep-all' => 1 }
> my $s = print_property_string($hash, 'prune-backups');
> # $hash is now {}, $s is 'keep-all=1'
> because validation is called in print_property_string. The same issue
> is present when calling prune_mark_backup_group.
>
> Because validation complains when keep-all and something else is set,
> this shouldn't have caused any real issues, besides vzdump with
> keep-all=1 wrongly taking the removal path, but without any settings,
> so not removing anything:
> INFO: prune older backups with retention:
> INFO: pruned 0 backup(s)
>
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
> PVE/Storage.pm | 5 ++---
> PVE/Storage/Plugin.pm | 7 ++++---
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
>
applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-09 16:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09 9:58 [pve-devel] [PATCH storage] prune {validate, mark}: preserve input parameter Fabian Ebner
2021-09-09 16:09 ` [pve-devel] applied: " Thomas Lamprecht
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal