]> git.proxmox.com Git - pve-guest-common.git/commitdiff
refactor config_with_pending_array
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 20 May 2020 15:08:09 +0000 (17:08 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 20 May 2020 15:08:09 +0000 (17:08 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/AbstractConfig.pm
PVE/GuestHelpers.pm

index f0c5440aa6c3c453ee73643fc16444e52a3ff45f..90e0b4cfd1058998a6e01bfb292e950d21889aa8 100644 (file)
@@ -82,7 +82,6 @@ sub parse_pending_delete {
     my $pending_deletions = {};
     for my $entry (split(/\s+/, $data)) {
        my ($force, $key) = $entry =~ /^(!?)(.*)$/;
-
        $pending_deletions->{$key} = {
            force => $force ? 1 : 0,
        };
index bc53b32c38f84b87cfd46ab7fd7e970af7b7feab..16ab3aca3c60945f0967d84ddb73e0c1e2cb7828 100644 (file)
@@ -201,40 +201,43 @@ sub format_pending {
 }
 
 # returns the config as an array of hashes, each hash can have the following keys:
-# key (the config property name, non-optional)
-# value (the current value in effect - if any)
-# pending (a new, still pending, value - if any)
-# delete (when deletions are pending, this is set to either 2 (force) or 1 (graceful))
+#  key: the config property name, non-optional
+#  value: the current value in effect - if any
+#  pending: a new, still pending, value - if any
+#  delete: when deletions are pending, this is set to either 2 (force) or 1 (graceful)
 sub config_with_pending_array {
     my ($conf, $pending_delete_hash) = @_;
 
-    my $res = [];
+    my $pending = delete $conf->{pending};
+    # we don't care for snapshots in pending and it makes our loops throw up
+    delete $conf->{snapshots};
 
+    my $res = [];
     foreach my $opt (keys %$conf) {
-       next if ref($conf->{$opt});
-       my $item = { key => $opt };
-       $item->{value} = $conf->{$opt} if defined($conf->{$opt});
-       $item->{pending} = $conf->{pending}->{$opt} if defined($conf->{pending}->{$opt});
-       $item->{delete} = ($pending_delete_hash->{$opt}->{force} ? 2 : 1) if exists $pending_delete_hash->{$opt};
+       my $item = {
+           key => $opt,
+           value => $conf->{$opt},
+       };
+       $item->{pending} = delete $pending->{$opt} if defined($conf->{pending}->{$opt});
+       my $delete = delete $pending_delete_hash->{$opt};
+       $item->{delete} = $delete->{force} ? 2 : 1 if defined($delete);
 
        push @$res, $item;
     }
 
-    foreach my $opt (keys %{$conf->{pending}}) {
+    foreach my $opt (keys %$pending) {
        next if $opt eq 'delete';
-       next if ref($conf->{pending}->{$opt}); # just to be sure
-       next if defined($conf->{$opt});
-       my $item = { key => $opt };
-       $item->{pending} = $conf->{pending}->{$opt};
-
-       push @$res, $item;
+       push @$res, {
+           key => $opt,
+           pending => $pending->{$opt},
+       };
     }
 
     while (my ($opt, $force) = each %$pending_delete_hash) {
-       next if defined($conf->{pending}->{$opt});
-       next if defined($conf->{$opt});
-       my $item = { key => $opt, delete => ($force ? 2 : 1)};
-       push @$res, $item;
+       push @$res, {
+           key => $opt,
+           delete => $force ? 2 : 1,
+       };
     }
 
     return $res;