From 3c55b139aa0371e7bace5ef9b76ff3c15fddca88 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 9 Sep 2018 10:52:18 +0200 Subject: Settings: Pull config file loading into function Signed-off-by: Florian Pritz --- lib/App/BorgRestore/Settings.pm | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/App/BorgRestore/Settings.pm b/lib/App/BorgRestore/Settings.pm index 8cbbf9c..31249c5 100644 --- a/lib/App/BorgRestore/Settings.pm +++ b/lib/App/BorgRestore/Settings.pm @@ -125,28 +125,33 @@ our @backup_prefixes = ( ); our $sqlite_cache_size = 102400; our $prepare_data_in_memory = 1; -my @configfiles; - -if (defined $ENV{XDG_CONFIG_HOME} or defined $ENV{HOME}) { - push @configfiles, sprintf("%s/borg-restore.cfg", $ENV{XDG_CONFIG_HOME} // $ENV{HOME}."/.config"); -} -push @configfiles, "/etc/borg-restore.cfg"; if (defined $ENV{XDG_CACHE_HOME} or defined $ENV{HOME}) { $cache_path_base = sprintf("%s/borg-restore.pl", $ENV{XDG_CACHE_HOME} // $ENV{HOME} ."/.cache"); } -for my $configfile (@configfiles) { - $configfile = App::BorgRestore::Helper::untaint($configfile, qr/.*/); - if (-e $configfile) { - unless (my $return = do $configfile) { - die "couldn't parse $configfile: $@" if $@; - die "couldn't do $configfile: $!" unless defined $return; - die "couldn't run $configfile" unless $return; +fun load_config_files() { + my @configfiles; + + if (defined $ENV{XDG_CONFIG_HOME} or defined $ENV{HOME}) { + push @configfiles, sprintf("%s/borg-restore.cfg", $ENV{XDG_CONFIG_HOME} // $ENV{HOME}."/.config"); + } + push @configfiles, "/etc/borg-restore.cfg"; + + for my $configfile (@configfiles) { + $configfile = App::BorgRestore::Helper::untaint($configfile, qr/.*/); + if (-e $configfile) { + unless (my $return = do $configfile) { + die "couldn't parse $configfile: $@" if $@; + die "couldn't do $configfile: $!" unless defined $return; + die "couldn't run $configfile" unless $return; + } } } } +load_config_files(); + if (not defined $cache_path_base) { die "Error: \$cache_path_base is not defined. This is most likely because the\n" ."environment variables \$HOME and \$XDG_CACHE_HOME are not set. Consider setting\n" -- cgit v1.2.3-24-g4f1b