]> git.proxmox.com Git - pve-guest-common.git/commitdiff
config: ensure definedness for iterating pending & snapshot volumes
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 16 Mar 2023 10:46:47 +0000 (11:46 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 16 Mar 2023 10:48:51 +0000 (11:48 +0100)
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 <t.lamprecht@proxmox.com>
src/PVE/AbstractConfig.pm

index d393081b2624e3b91146f940eceb6926ed370f44..fcc9738f079956bf4472446d2b119e47ae5a547b 100644 (file)
@@ -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.