]> git.proxmox.com Git - pve-guest-common.git/commitdiff
cleanup_pending: refactor and fix $force
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 18:31:10 +0000 (20:31 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 18:32:30 +0000 (20:32 +0200)
pull out $conf->{pending} in a intermediate variable.

While for now only a force key could be in a pending delete value it
still is completely wrong to say the whole hash value is thus $force.

Fix that by omitting that intermediate variable completely and copy
over directly from the source hash.

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

index 71a9e7c243f919d567f3b92c094dde7ed80d2bbe..a94a379fee0eb82647c765b9b300356295999e85 100644 (file)
@@ -138,30 +138,31 @@ sub remove_from_pending_delete {
 sub cleanup_pending {
     my ($class, $conf) = @_;
 
+    my $pending = $conf->{pending};
     # remove pending changes when nothing changed
     my $changes;
     foreach my $opt (keys %{$conf->{pending}}) {
        next if $opt eq 'delete'; # just to be sure
-       if (defined($conf->{$opt}) && ($conf->{pending}->{$opt} eq  $conf->{$opt})) {
+       if (defined($conf->{$opt}) && ($pending->{$opt} eq  $conf->{$opt})) {
            $changes = 1;
-           delete $conf->{pending}->{$opt};
+           delete $pending->{$opt};
        }
     }
 
-    my $current_delete_hash = $class->parse_pending_delete($conf->{pending}->{delete});
+    my $current_delete_hash = $class->parse_pending_delete($pending->{delete});
     my $pending_delete_hash = {};
-    while (my ($opt, $force) = each %$current_delete_hash) {
+    for my $opt (keys %$current_delete_hash) {
        if (defined($conf->{$opt})) {
-           $pending_delete_hash->{$opt} = $force;
+           $pending_delete_hash->{$opt} = $current_delete_hash->{$opt};
        } else {
            $changes = 1;
        }
     }
 
     if (%$pending_delete_hash) {
-       $conf->{pending}->{delete} = $class->print_pending_delete($pending_delete_hash);
+       $pending->{delete} = $class->print_pending_delete($pending_delete_hash);
     } else {
-       delete $conf->{pending}->{delete};
+       delete $pending->{delete};
     }
 
     return $changes;