]> git.proxmox.com Git - pve-guest-common.git/commitdiff
refactor parse_pending_delete to sane implemenation
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 14:43:25 +0000 (16:43 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 15:48:03 +0000 (17:48 +0200)
this was quite the mess, a perl greedy match over non-whitespace
character is equivalent to a split on whitespace on, but the latter
is much easier to grasp when looking at this the first time.

Do a real for loop with real variable names and less nest everything
into one line.

the test added in the previous commit should give use the safety net
for that cleanup.

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

index 2fe30f7a746278f1b7a41b9037dcf02a73937521..16ba427e96485aeb8a14266f0e247220390e6715 100644 (file)
@@ -72,10 +72,22 @@ sub write_config {
 
 sub parse_pending_delete {
     my ($class, $data) = @_;
-    $data ||= '';
+
+    return {} if !$data;
+
     $data =~ s/[,;]/ /g;
     $data =~ s/^\s+//;
-    return { map { /^(!?)(.*)$/ && ($2, { 'force' => $1 eq '!' ? 1 : 0 } ) } ($data =~ /\S+/g) };
+
+    my $pending_deletions = {};
+    for my $entry (split(/\s+/, $data)) {
+       my ($force, $key) = $entry =~ /^(!?)(.*)$/;
+
+       $pending_deletions->{$key} = {
+           force => $force ? 1 : 0,
+       };
+    }
+
+    return $pending_deletions;
 }
 
 sub print_pending_delete {