]> git.proxmox.com Git - pve-guest-common.git/commitdiff
refactor/cleanup add_to_pending_delete sligthly
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 17:27:31 +0000 (19:27 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 17:35:06 +0000 (19:35 +0200)
no need to delete, then re-fill by autovification; just explicitly
overwrite with new value.

Also explicitly populate pending hash if not defined, avoids
auto-vivification which is a bit intransparent.

explicitly return $conf for tests

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/AbstractConfig.pm

index 698db58959645f51b36f07b38809acd437c01201..b07ef5936131c95dbf517ac9c683b9c6a0c6b69b 100644 (file)
@@ -105,10 +105,15 @@ sub print_pending_delete {
 sub add_to_pending_delete {
     my ($class, $conf, $key, $force) = @_;
 
-    delete $conf->{pending}->{$key};
-    my $pending_delete_hash = $class->parse_pending_delete($conf->{pending}->{delete});
-    $pending_delete_hash->{$key}->{force} = $force;
-    $conf->{pending}->{delete} = $class->print_pending_delete($pending_delete_hash);
+    $conf->{pending} //= {};
+    my $pending = $conf->{pending};
+    my $pending_delete_hash = $class->parse_pending_delete($pending->{delete});
+
+    $pending_delete_hash->{$key} = { force => $force };
+
+    $pending->{delete} = $class->print_pending_delete($pending_delete_hash);
+
+    return $conf;
 }
 
 sub remove_from_pending_delete {