summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-08-17 15:12:39 +0200
committerFlorian Pritz <bluewind@xinu.at>2018-08-17 15:12:39 +0200
commitc891e552a0cf4f937a541ff4a220ecec529cbdc2 (patch)
tree40970b06a7b62aaf49de310cfe64f2ccfad11250
parent4bf9db2df37f151d388612924fcb9a7e60300329 (diff)
downloadApp-BorgRestore-c891e552a0cf4f937a541ff4a220ecec529cbdc2.tar.gz
App-BorgRestore-c891e552a0cf4f937a541ff4a220ecec529cbdc2.tar.xz
Die when XDG_* and HOME env vars are not set
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--lib/App/BorgRestore/Settings.pm22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/App/BorgRestore/Settings.pm b/lib/App/BorgRestore/Settings.pm
index faad58f..7bf9664 100644
--- a/lib/App/BorgRestore/Settings.pm
+++ b/lib/App/BorgRestore/Settings.pm
@@ -105,16 +105,21 @@ See LICENSE for the full license text.
=cut
our $borg_repo = "backup:borg-".hostname;
-our $cache_path_base = sprintf("%s/borg-restore.pl", $ENV{XDG_CACHE_HOME} // $ENV{HOME}."/.cache");
+our $cache_path_base;
our @backup_prefixes = (
{regex => "^/", replacement => ""},
);
our $sqlite_cache_size = 102400;
+my @configfiles;
-my @configfiles = (
- sprintf("%s/borg-restore.cfg", $ENV{XDG_CONFIG_HOME} // $ENV{HOME}."/.config"),
- "/etc/borg-restore.cfg",
-);
+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/.*/);
@@ -126,6 +131,13 @@ for my $configfile (@configfiles) {
}
}
}
+
+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"
+ ."the path in the config file or ensure that the variables are set.";
+}
+
$cache_path_base = App::BorgRestore::Helper::untaint($cache_path_base, qr/.*/);
sub get_cache_base_dir_path {