From 9b1c87033b7a4aa12ea607081c836c6e614a492c Mon Sep 17 00:00:00 2001 From: luccioman Date: Fri, 31 Aug 2018 08:34:28 +0200 Subject: [PATCH] Fixed logs folder checking and creation Previously, if YaCy log folder was for example at `/home/user/yacy/DATA/LOG`, because of improper truncation of log path, an unnecessary directory creation was atempted at `/home/us`. --- source/net/yacy/cora/util/ConcurrentLog.java | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/source/net/yacy/cora/util/ConcurrentLog.java b/source/net/yacy/cora/util/ConcurrentLog.java index 0f050f164..7a759c5b0 100644 --- a/source/net/yacy/cora/util/ConcurrentLog.java +++ b/source/net/yacy/cora/util/ConcurrentLog.java @@ -390,12 +390,24 @@ public final class ConcurrentLog { // creating the logging directory String logPattern = logManager.getProperty("java.util.logging.FileHandler.pattern"); - int stripPos = logPattern.lastIndexOf(File.separatorChar); - if (!new File(logPattern).isAbsolute()) logPattern = new File(dataPath, logPattern).getAbsolutePath(); - if (stripPos < 0) stripPos = logPattern.lastIndexOf(File.separatorChar); - File log = new File(logPattern.substring(0, stripPos)); - if (!log.isAbsolute()) log = new File(dataPath, log.getPath()); - if (!log.canRead()) log.mkdir(); + File logFile = new File(logPattern); + if (!logFile.isAbsolute()) { + logFile = new File(dataPath, logPattern); + logPattern = logFile.getAbsolutePath(); + } + File logDirectory = logFile.getParentFile(); + if(logDirectory != null) { + if (!logDirectory.isAbsolute()) { + logDirectory = new File(dataPath, logDirectory.getPath()); + } + if (!logDirectory.exists()) { + if(!logDirectory.mkdir()) { + System.err.println("STARTUP: Could not create the logs directory at " + logDirectory.getAbsolutePath()); + } + } else if(!logDirectory.isDirectory()) { + System.err.println("STARTUP: Log file parent path at " + logDirectory.getAbsolutePath() + "is not a directory"); + } + } // generating the root logger final Logger logger = Logger.getLogger("");