From c4e6a2f0a8095f9b60c5b693a4cd373c9a37d26a Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Mon, 19 Jul 2004 17:18:49 +0000
Subject: [PATCH] if the log pattern/path referenced doesn't exist, create all
 necessary parent directories (killing the JVM if it fails, rather than
 silently gobble the log messages to /dev/null)

---
 core/java/src/net/i2p/util/LogWriter.java | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/core/java/src/net/i2p/util/LogWriter.java b/core/java/src/net/i2p/util/LogWriter.java
index c8b26dc299..54a2c9eef9 100644
--- a/core/java/src/net/i2p/util/LogWriter.java
+++ b/core/java/src/net/i2p/util/LogWriter.java
@@ -122,6 +122,18 @@ class LogWriter implements Runnable {
         File f = getNextFile(pattern);
         _currentFile = f;
         _numBytesInCurrentFile = 0;
+        File parent = f.getParentFile();
+        if (!parent.exists()) {
+            boolean ok = parent.mkdirs();
+            if (!ok) {
+                System.err.println("Unable to create the parent directy: " + parent.getAbsolutePath());
+                System.exit(0);
+            }
+        }
+        if (!parent.isDirectory()) {
+            System.err.println("wtf, we cannot put the logs in a subdirectory of a plain file!  we want to stre the log as " + f.getAbsolutePath());
+            System.exit(0);
+        }
         try {
             _currentOut = new FileOutputStream(f);
         } catch (IOException ioe) {
-- 
GitLab