btrbk: fix fallback_default_config

- add for action-archive
- exit if config is present but has parse errors
pull/293/head
Axel Burri 2019-08-05 14:31:48 +02:00
parent 3e40903720
commit 8b93ef7c82
1 changed files with 26 additions and 20 deletions

46
btrbk
View File

@ -3964,23 +3964,24 @@ sub init_config(@)
}
sub parse_config(@)
{
sub _config_file(@) {
my @config_files = @_;
my $file = undef;
foreach(@config_files) {
TRACE "config: checking for file: $_";
if(-r "$_") {
$file = $_;
last;
}
foreach my $file (@config_files) {
TRACE "config: checking for file: $file";
return $file if(-r "$file");
}
return undef;
}
sub parse_config($)
{
my $file = shift;
return undef unless($file);
my $root = init_config(SRC_FILE => $file);
my $cur = $root;
INFO "Using configuration: $file";
TRACE "config: open configuration file: $file";
open(FILE, '<', $file) or die $!;
while (<FILE>) {
chomp;
@ -4992,6 +4993,7 @@ MAIN:
}
elsif ($command eq "archive") {
$action_archive = 1;
$fallback_default_config = 1;
$args_expected_min = $args_expected_max = 2;
@subvol_args = @ARGV;
}
@ -5144,17 +5146,21 @@ MAIN:
#
# parse config file
#
my $config = parse_config(@config_src);
unless($config) {
if($fallback_default_config) {
INFO "Configuration file not found, falling back to defaults";
$config = init_config();
}
else {
ERROR "Configuration file not found: " . join(', ', @config_src);
exit 2;
}
my $config;
if(my $config_file = _config_file(@config_src)) {
INFO "Using configuration: $config_file";
$config = parse_config($config_file);
exit 2 unless($config);
}
elsif($fallback_default_config) {
INFO "Configuration file not found, falling back to defaults";
$config = init_config();
}
else {
ERROR "Configuration file not found: " . join(', ', @config_src);
exit 2;
}
unless(ref($config->{SUBSECTION}) eq "ARRAY") {
ERROR "No volumes defined in configuration file";
exit 2;