mirror of https://github.com/digint/btrbk
btrbk: fix fallback_default_config
- add for action-archive - exit if config is present but has parse errorspull/293/head
parent
3e40903720
commit
8b93ef7c82
46
btrbk
46
btrbk
|
@ -3964,23 +3964,24 @@ sub init_config(@)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub parse_config(@)
|
sub _config_file(@) {
|
||||||
{
|
|
||||||
my @config_files = @_;
|
my @config_files = @_;
|
||||||
my $file = undef;
|
foreach my $file (@config_files) {
|
||||||
foreach(@config_files) {
|
TRACE "config: checking for file: $file";
|
||||||
TRACE "config: checking for file: $_";
|
return $file if(-r "$file");
|
||||||
if(-r "$_") {
|
|
||||||
$file = $_;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub parse_config($)
|
||||||
|
{
|
||||||
|
my $file = shift;
|
||||||
return undef unless($file);
|
return undef unless($file);
|
||||||
|
|
||||||
my $root = init_config(SRC_FILE => $file);
|
my $root = init_config(SRC_FILE => $file);
|
||||||
my $cur = $root;
|
my $cur = $root;
|
||||||
|
|
||||||
INFO "Using configuration: $file";
|
TRACE "config: open configuration file: $file";
|
||||||
open(FILE, '<', $file) or die $!;
|
open(FILE, '<', $file) or die $!;
|
||||||
while (<FILE>) {
|
while (<FILE>) {
|
||||||
chomp;
|
chomp;
|
||||||
|
@ -4992,6 +4993,7 @@ MAIN:
|
||||||
}
|
}
|
||||||
elsif ($command eq "archive") {
|
elsif ($command eq "archive") {
|
||||||
$action_archive = 1;
|
$action_archive = 1;
|
||||||
|
$fallback_default_config = 1;
|
||||||
$args_expected_min = $args_expected_max = 2;
|
$args_expected_min = $args_expected_max = 2;
|
||||||
@subvol_args = @ARGV;
|
@subvol_args = @ARGV;
|
||||||
}
|
}
|
||||||
|
@ -5144,17 +5146,21 @@ MAIN:
|
||||||
#
|
#
|
||||||
# parse config file
|
# parse config file
|
||||||
#
|
#
|
||||||
my $config = parse_config(@config_src);
|
my $config;
|
||||||
unless($config) {
|
if(my $config_file = _config_file(@config_src)) {
|
||||||
if($fallback_default_config) {
|
INFO "Using configuration: $config_file";
|
||||||
INFO "Configuration file not found, falling back to defaults";
|
$config = parse_config($config_file);
|
||||||
$config = init_config();
|
exit 2 unless($config);
|
||||||
}
|
|
||||||
else {
|
|
||||||
ERROR "Configuration file not found: " . join(', ', @config_src);
|
|
||||||
exit 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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") {
|
unless(ref($config->{SUBSECTION}) eq "ARRAY") {
|
||||||
ERROR "No volumes defined in configuration file";
|
ERROR "No volumes defined in configuration file";
|
||||||
exit 2;
|
exit 2;
|
||||||
|
|
Loading…
Reference in New Issue