btrbk: tidy function prototype

pull/485/head
Axel Burri 2022-06-06 16:20:53 +02:00
parent f169456613
commit fb13848faf
1 changed files with 12 additions and 9 deletions

21
btrbk
View File

@ -4198,9 +4198,12 @@ sub append_config_option($$$$;@)
} }
sub parse_config_line($$$$$) sub parse_config_line($$$;@)
{ {
my ($file, $root, $cur, $key, $value) = @_; my ($cur, $key, $value, %opts) = @_;
my $root = $cur;
$root = $root->{PARENT} while($root->{CONTEXT} ne "global");
my $error_statement = $opts{error_statement} // "";
if($key eq "volume") if($key eq "volume")
{ {
@ -4208,7 +4211,7 @@ sub parse_config_line($$$$$)
TRACE "config: context forced to: $cur->{CONTEXT}" if($do_trace); TRACE "config: context forced to: $cur->{CONTEXT}" if($do_trace);
# be very strict about file options, for security sake # be very strict about file options, for security sake
my ($url_prefix, $path) = check_url($value, error_statement => "for option \"$key\" in \"$file\" line $."); my ($url_prefix, $path) = check_url($value, error_statement => "for option \"$key\" $error_statement");
return undef unless(defined($path)); return undef unless(defined($path));
TRACE "config: adding volume \"$url_prefix$path\" to global context" if($do_trace); TRACE "config: adding volume \"$url_prefix$path\" to global context" if($do_trace);
die unless($cur->{CONTEXT} eq "global"); die unless($cur->{CONTEXT} eq "global");
@ -4244,7 +4247,7 @@ sub parse_config_line($$$$$)
$url = ($rel_path eq '.') ? $cur->{url} : $cur->{url} . '/' . $rel_path; $url = ($rel_path eq '.') ? $cur->{url} : $cur->{url} . '/' . $rel_path;
} }
else { else {
my ($url_prefix, $path) = check_url($value, accept_wildcards => 1, error_statement => "for option \"$key\"" . ($cur->{DUMMY} ? " (if no \"volume\" section is declared)" : "") . " in \"$file\" line $."); my ($url_prefix, $path) = check_url($value, accept_wildcards => 1, error_statement => "for option \"$key\"" . ($cur->{DUMMY} ? " (if no \"volume\" section is declared)" : "") . " $error_statement");
return undef unless(defined($path)); return undef unless(defined($path));
$url = $url_prefix . $path; $url = $url_prefix . $path;
} }
@ -4277,11 +4280,11 @@ sub parse_config_line($$$$$)
my $target_type = $+{target_type} // "send-receive"; my $target_type = $+{target_type} // "send-receive";
my $url = $+{url}; my $url = $+{url};
unless(grep(/^\Q$target_type\E$/, @config_target_types)) { unless(grep(/^\Q$target_type\E$/, @config_target_types)) {
ERROR "Unknown target type \"$target_type\" in \"$file\" line $."; ERROR "Unknown target type \"$target_type\" $error_statement";
return undef; return undef;
} }
# be very strict about file options, for security sake # be very strict about file options, for security sake
my ($url_prefix, $path) = check_url($url, error_statement => "for option \"$key\" in \"$file\" line $."); my ($url_prefix, $path) = check_url($url, error_statement => "for option \"$key\" $error_statement");
return undef unless(defined($path)); return undef unless(defined($path));
TRACE "config: adding target \"$url_prefix$path\" (type=$target_type) to $cur->{CONTEXT} context" . ($cur->{url} ? ": $cur->{url}" : "") if($do_trace); TRACE "config: adding target \"$url_prefix$path\" (type=$target_type) to $cur->{CONTEXT} context" . ($cur->{url} ? ": $cur->{url}" : "") if($do_trace);
@ -4297,13 +4300,13 @@ sub parse_config_line($$$$$)
} }
else else
{ {
ERROR "Ambiguous target configuration, in \"$file\" line $."; ERROR "Ambiguous target configuration $error_statement";
return undef; return undef;
} }
} }
else else
{ {
return append_config_option($cur, $key, $value, $cur->{CONTEXT}, error_statement => "in \"$file\" line $."); return append_config_option($cur, $key, $value, $cur->{CONTEXT}, error_statement => $error_statement);
} }
return $cur; return $cur;
@ -4403,7 +4406,7 @@ sub parse_config($)
my ($indent, $key, $value) = (length($1), lc($2), $4 // ""); my ($indent, $key, $value) = (length($1), lc($2), $4 // "");
$value =~ s/^"(.*)"$/$1/; $value =~ s/^"(.*)"$/$1/;
$value =~ s/^'(.*)'$/$1/; $value =~ s/^'(.*)'$/$1/;
$cur = parse_config_line($file, $root, $cur, $key, $value); $cur = parse_config_line($cur, $key, $value, error_statement => "in \"$file\" line $.");
unless(defined($cur)) { unless(defined($cur)) {
# error, bail out # error, bail out
$root = undef; $root = undef;