A little defensive coding around last_post.txt.
authorJason Stephenson <jstephenson@mvlc.org>
Thu, 21 Mar 2013 13:24:30 +0000 (09:24 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Thu, 21 Mar 2013 13:24:30 +0000 (09:24 -0400)
If the file doesn't exist, rather than die, try to create it.  Only
die if we fail to create it.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
iNCIPit.cgi

index 28adba7..e1165f7 100644 (file)
@@ -48,10 +48,15 @@ close POST_DATA;
 # XXX: just the most recently posted ncip message filename should be in config.
 {
     local $/ = undef;
-    open FILE, "last_post.txt" or die "Couldn't open file: $!";
-    binmode FILE;
-    $prev_xml = <FILE>;
-    close FILE;
+    if (open FILE, "last_post.txt") {
+        binmode FILE;
+        $prev_xml = <FILE>;
+        close FILE;
+    } else {
+        # poor man's creat.
+        (open(FILE, ">last_post.txt") && close(FILE))
+            or die "Couldn't create file: $!";
+    }
 }
 
 # fail as gracefully as possible if repeat post has occured