From 68d5fe3f552a388d739fd4212c908c0b70bf3eb4 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Sun, 6 Feb 2022 16:09:32 +0100 Subject: [PATCH] btrbk: add match argument in config_key --- btrbk | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/btrbk b/btrbk index b6cc378..cc1c799 100755 --- a/btrbk +++ b/btrbk @@ -3900,24 +3900,35 @@ sub check_url($;@) } -sub config_key($$) +sub config_key($$;$) { my $config = shift || die; my $key = shift || die; + my $match = shift; $config = $config->{CONFIG} if($config->{CONFIG}); # accept vinfo for $config + my $val; if(exists($config_override{$key})) { TRACE "config_key: OVERRIDE key=$key to value=" . ($config_override{$key} // "") if($do_trace); - return $config_override{$key}; + $val = $config_override{$key}; } + else { + while(not exists($config->{$key})) { + # note: while all config keys exist in "meta" context (at least with default values), + # we also allow fake configs (CONTEXT="cmdline") which have no PARENT. + return undef unless($config->{PARENT}); + $config = $config->{PARENT}; + } + $val = $config->{$key}; + } + return undef unless defined($val); + return $val unless defined($match); - while(not exists($config->{$key})) { - # note: while all config keys exist in "meta" context (at least with default values), - # we also allow fake configs (CONTEXT="cmdline") which have no PARENT. - return undef unless($config->{PARENT}); - $config = $config->{PARENT}; + if(ref($val) eq "ARRAY") { + return grep(/^$match$/, @$val) ? $match : undef; + } else { + return ($val eq $match) ? $match : undef; } - return $config->{$key}; }