commit e430fe2bc011bf37aa658b79b85045c3f03ed12f Author: Karsten Loesing karsten.loesing@gmx.net Date: Sun Apr 26 19:39:59 2015 +0200
Actually support --update-only and later --write-only. --- .../java/org/torproject/onionoo/cron/Main.java | 4 ++++ .../org/torproject/onionoo/docs/DocumentStore.java | 21 +++++++++----------- .../org/torproject/onionoo/server/NodeIndexer.java | 7 +++---- 3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/cron/Main.java b/src/main/java/org/torproject/onionoo/cron/Main.java index 2f45cea..6f39cb6 100644 --- a/src/main/java/org/torproject/onionoo/cron/Main.java +++ b/src/main/java/org/torproject/onionoo/cron/Main.java @@ -2,6 +2,7 @@ * See LICENSE for licensing information */ package org.torproject.onionoo.cron;
+import java.io.File; import java.util.Calendar; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -141,6 +142,8 @@ public class Main implements Runnable {
private DocumentStore ds;
+ private File outDir = new File("out"); + private StatusUpdateRunner sur;
private DocumentWriterRunner dwr; @@ -160,6 +163,7 @@ public class Main implements Runnable { this.log.info("Initialized status update runner"); } if (!this.downloadOnly && !this.updateOnly) { + this.ds.setOutDir(outDir); this.dwr = new DocumentWriterRunner(); this.log.info("Initialized document writer runner"); } diff --git a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java index 69646f1..3d2ae7a 100644 --- a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java +++ b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java @@ -10,7 +10,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -45,12 +44,8 @@ public class DocumentStore {
private final File statusDir = new File("status");
- private File outDir = new File("out"); - public void setOutDir(File outDir) throws FileNotFoundException { - if (!outDir.exists() || !outDir.isDirectory()) { - throw new FileNotFoundException("Cannot access directory " - + outDir); - } + private File outDir = null; + public void setOutDir(File outDir) { this.outDir = outDir; }
@@ -156,9 +151,8 @@ public class DocumentStore { private void cacheSummaryDocuments() { SortedMap<String, SummaryDocument> parsedSummaryDocuments = new TreeMap<String, SummaryDocument>(); - File directory = this.outDir; - if (directory != null) { - File summaryFile = new File(directory, "summary"); + if (this.outDir != null) { + File summaryFile = new File(this.outDir, "summary"); if (summaryFile.exists()) { String line = null; try { @@ -757,6 +751,10 @@ public class DocumentStore { }
private void writeSummaryDocuments() { + if (this.outDir == null) { + /* Can't write out/summary without knowing the path of out/. */ + return; + } StringBuilder sb = new StringBuilder(); Gson gson = new Gson(); for (SummaryDocument summaryDocument : @@ -786,8 +784,7 @@ public class DocumentStore {
private void writeUpdateStatus() { if (this.outDir == null) { - log.error("Unable to write update status file without knowing the " - + "'out' directory to write to!"); + /* Can't write out/update without knowing the path of out/. */ return; } UpdateStatus updateStatus = new UpdateStatus(); diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java index 64cf3a9..5788d4e 100644 --- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java +++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java @@ -35,14 +35,13 @@ public class NodeIndexer implements ServletContextListener, Runnable { public void contextInitialized(ServletContextEvent contextEvent) { ServletContext servletContext = contextEvent.getServletContext(); File outDir = new File(servletContext.getInitParameter("outDir")); - DocumentStore documentStore = DocumentStoreFactory.getDocumentStore(); - try { - documentStore.setOutDir(outDir); - } catch(FileNotFoundException fnfe) { + if (!outDir.exists() || !outDir.isDirectory()) { log.error("\n\n\tOut-dir not found! Expected directory: " + outDir + "\n\tVerify the configuration in ./etc/web.xml.template"); System.exit(1); } + DocumentStore documentStore = DocumentStoreFactory.getDocumentStore(); + documentStore.setOutDir(outDir); /* The servlet container created us, and we need to avoid that * ApplicationFactory creates another instance of us. */ NodeIndexerFactory.setNodeIndexer(this);