From c95b563b7be8e8a09c190a78cbdbfc0a61fb82b6 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 16 Mar 2023 11:46:47 +0100 Subject: [PATCH] config: ensure definedness for iterating pending & snapshot volumes while it will work as is, autovivification can be a real PITA so this should make it more robust and might even avoid having the one or other warning about accessing undef values in logs. Signed-off-by: Thomas Lamprecht --- src/PVE/AbstractConfig.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm index d393081..fcc9738 100644 --- a/src/PVE/AbstractConfig.pm +++ b/src/PVE/AbstractConfig.pm @@ -508,12 +508,17 @@ sub update_volume_ids { }; $class->foreach_volume_full($conf, $opts, $do_replace, $conf); - foreach my $snap (keys %{$conf->{snapshots}}) { - my $snap_conf = $conf->{snapshots}->{$snap}; - $class->foreach_volume_full($snap_conf, $opts, $do_replace, $snap_conf); + + if (defined($conf->{snapshots})) { + for my $snap (keys %{$conf->{snapshots}}) { + my $snap_conf = $conf->{snapshots}->{$snap}; + $class->foreach_volume_full($snap_conf, $opts, $do_replace, $snap_conf); + } } - $class->foreach_volume_full($conf->{pending}, $opts, $do_replace, $conf->{pending}); + if (defined($conf->{pending})) { + $class->foreach_volume_full($conf->{pending}, $opts, $do_replace, $conf->{pending}); + } } # Returns whether the template parameter is set in $conf.