From 7b9d1adeb25d0bc8b65292f27e457dec74e85ff8 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 18 Oct 2019 16:43:25 +0200 Subject: [PATCH] refactor parse_pending_delete to sane implemenation 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 --- PVE/AbstractConfig.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm index 2fe30f7..16ba427 100644 --- a/PVE/AbstractConfig.pm +++ b/PVE/AbstractConfig.pm @@ -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 {