Skip to content
Browse files

Check if directories exist at startup.

  • Loading branch information...
1 parent 9ddb990 commit 1202094b504f1be41b253638ad695ee40b4b751b Jonas Kramer committed Aug 7, 2011
Showing with 8 additions and 1 deletion.
  1. +8 −1 post-fm
View
9 post-fm
@@ -14,6 +14,7 @@ use Digest::MD5;
use LWP::UserAgent;
use Storable;
use POSIX qw( strftime );
+use File::Basename;
# Globals. {{{
our %rc = (
@@ -40,6 +41,12 @@ our $time = time;
our $tracks = [];
# }}}
+# Check if paths are available first.
+for my $file ($rc{pid}, $rc{cache}) {
+ my $path = dirname($file);
+ die "$path does not exist or is not a directory.\n" unless(-d $path);
+}
+
# Kill our old self. {{{
# If our predecessor is still alive, send it the ALRM signal to wake it up (if
# it's sleeping). Give it 10 seconds to submit it's track data and exit. If
@@ -85,7 +92,7 @@ my %data = @ARGV;
my $pid = fork;
if($pid) {
- open PID, ">", $rc{pid};
+ open PID, ">", $rc{pid} or die "Can't write $rc{pid}. $!.\n";
print PID $pid, "\n";
close PID;
exit;

0 comments on commit 1202094

Please sign in to comment.
Something went wrong with that request. Please try again.