mirror of
https://git.proxmox.com/git/pve-guest-common
synced 2025-07-25 10:03:45 +00:00
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 <t.lamprecht@proxmox.com>
This commit is contained in:
parent
fe82406191
commit
7b9d1adeb2
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user