Make sure configdir exists before die if we can't write to a file in that dir..

This commit is contained in:
2019-08-26 02:20:35 +02:00
parent b63c0f9645
commit 72c47557a9

8
pcurse
View File

@ -7,7 +7,11 @@ use Data::Dumper;
use lib '.';
use pcurse;
my $logfile = $ENV{'HOME'}.'/.pcurse/lastrun.log';
my $confdir = $ENV{'HOME'}.'/.pcurse/';
#Make sure ~/.pcurse exists
system('mkdir','-p',$confdir) unless(-d $confdir);
my $logfile = $confdir.'lastrun.log';
open my $lf, '>', $logfile or die 'Cannot write to logfile '.$logfile.': '.$!;
select STDOUT;
$| = 1;
@ -20,7 +24,7 @@ my @toupd;
my %jobs;
my $workers;
my $opts = pcurse::parse_arguments;
$opts->{'config'} = $ENV{'HOME'}.'/.pcurse/config.json' unless(defined($opts->{'config'}));
$opts->{'config'} = $confdir.'config.json' unless(defined($opts->{'config'}));
my $conf = pcurse::load_config($opts->{'config'});
$conf = pcurse::check_config($conf);
($ret,$msg) = pcurse::save_config($conf->{'config'},$conf);