Create recent alert file if not exists.

die()'ing here didn't make much sense.  If the file isn't there, we
don't have any recent alerts, so an empty file and returning and empty
hash fine.

Note this doesn't test if the directory is empty.
This commit is contained in:
Bradley M. Kuhn 2016-01-18 10:31:40 -08:00
parent 0d4f6aae9e
commit 8b78e44bc4

View file

@ -35,7 +35,12 @@ sub ReadRecentWeatherAlerts ($) {
my %info; my %info;
my $file = File::Spec->catfile($dir, 'conky-weather-alert-recent'); my $file = File::Spec->catfile($dir, 'conky-weather-alert-recent');
open(RECENT_ALERTS, "<", $file) or die "unable to open $file for reading: $!"; unless (open(RECENT_ALERTS, "<", $file)) {
# If the file doesn't exist, create it empty.
warn "unable to open $file for reading: $! (will recreate)";
WriteRecentWeatherAlerts($dir, {});
return {};
}
my $key; my $key;
my $data = ""; my $data = "";
foreach my $line (<RECENT_ALERTS>) { foreach my $line (<RECENT_ALERTS>) {