[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] task-14024 log dramatic error message for missing outdir and exit web-server.



commit b22033332a4441ba3568858aac91f5cd3ba09757
Author: iwakeh <iwakeh@xxxxxxxxxxxxxxxxxxxx>
Date:   Fri Jan 2 19:50:00 2015 +0000

    task-14024 log dramatic error message for missing outdir and exit web-server.
---
 .../java/org/torproject/onionoo/docs/DocumentStore.java |    7 ++++++-
 .../java/org/torproject/onionoo/server/NodeIndexer.java |   15 ++++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
index a880e53..054fe3b 100644
--- a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
+++ b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
@@ -10,6 +10,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -45,7 +46,11 @@ public class DocumentStore {
   private final File statusDir = new File("status");
 
   private File outDir = new File("out");
-  public void setOutDir(File outDir) {
+  public void setOutDir(File outDir) throws FileNotFoundException {
+    if (!outDir.exists() || !outDir.isDirectory()) {
+      throw new FileNotFoundException("Cannot access directory "
+          + outDir);
+    }
     this.outDir = outDir;
   }
 
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index 1a67cc5..64cf3a9 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -1,6 +1,7 @@
 package org.torproject.onionoo.server;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -16,6 +17,9 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.torproject.onionoo.docs.DocumentStore;
 import org.torproject.onionoo.docs.DocumentStoreFactory;
 import org.torproject.onionoo.docs.SummaryDocument;
@@ -25,11 +29,20 @@ import org.torproject.onionoo.util.TimeFactory;
 
 public class NodeIndexer implements ServletContextListener, Runnable {
 
+  private static final Logger log = LoggerFactory.getLogger(
+      NodeIndexer.class);
+
   public void contextInitialized(ServletContextEvent contextEvent) {
     ServletContext servletContext = contextEvent.getServletContext();
     File outDir = new File(servletContext.getInitParameter("outDir"));
     DocumentStore documentStore = DocumentStoreFactory.getDocumentStore();
-    documentStore.setOutDir(outDir);
+    try {
+      documentStore.setOutDir(outDir);
+    } catch(FileNotFoundException fnfe) {
+      log.error("\n\n\tOut-dir not found! Expected directory: " + outDir
+          + "\n\tVerify the configuration in ./etc/web.xml.template");
+      System.exit(1);
+    }
     /* The servlet container created us, and we need to avoid that
      * ApplicationFactory creates another instance of us. */
     NodeIndexerFactory.setNodeIndexer(this);

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits