commit 3b142e9658ed56f735514694691c74ee18099f99
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Fri Aug 23 09:13:29 2013 +0200
Don't assume that in/ and out/ directories exist.
Spotted by Sebastian.
---
src/org/torproject/onionoo/DescriptorSource.java | 12 +++++++++---
src/org/torproject/onionoo/DocumentStore.java | 2 ++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/org/torproject/onionoo/DescriptorSource.java b/src/org/torproject/onionoo/DescriptorSource.java
index 89fd1de..2bac013 100644
--- a/src/org/torproject/onionoo/DescriptorSource.java
+++ b/src/org/torproject/onionoo/DescriptorSource.java
@@ -110,8 +110,14 @@ class DescriptorQueue {
+ "to descriptor reader.");
return;
}
- this.descriptorReader.addDirectory(new File(this.inDir,
- directoryName));
+ File directory = new File(this.inDir, directoryName);
+ if (directory.exists() && directory.isDirectory()) {
+ this.descriptorReader.addDirectory(directory);
+ } else {
+ System.err.println("Directory " + directory.getAbsolutePath()
+ + " either does not exist or is not a directory. Not adding "
+ + "to descriptor reader.");
+ }
}
public void readHistoryFile(DescriptorHistory descriptorHistory) {
@@ -147,7 +153,7 @@ class DescriptorQueue {
return;
}
this.historyFile = new File(this.statusDir, historyFileName);
- if (this.historyFile.exists()) {
+ if (this.historyFile.exists() && this.historyFile.isFile()) {
SortedMap<String, Long> excludedFiles = new TreeMap<String, Long>();
try {
BufferedReader br = new BufferedReader(new FileReader(
diff --git a/src/org/torproject/onionoo/DocumentStore.java b/src/org/torproject/onionoo/DocumentStore.java
index 2271bf7..28fc0e6 100644
--- a/src/org/torproject/onionoo/DocumentStore.java
+++ b/src/org/torproject/onionoo/DocumentStore.java
@@ -455,6 +455,7 @@ public class DocumentStore {
}
String documentString = sb.toString();
try {
+ summaryFile.getParentFile().mkdirs();
BufferedWriter bw = new BufferedWriter(new FileWriter(summaryFile));
bw.write(documentString);
bw.close();
@@ -474,6 +475,7 @@ public class DocumentStore {
File updateFile = new File(this.outDir, "update");
String documentString = String.valueOf(System.currentTimeMillis());
try {
+ updateFile.getParentFile().mkdirs();
BufferedWriter bw = new BufferedWriter(new FileWriter(updateFile));
bw.write(documentString);
bw.close();