Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Try to make parent directories for --log-pattern path. Fixes BUKKIT-680

  • Loading branch information...
commit be7a79c48fd732bea544ad05a59540ed274143d3 1 parent 5a11b0d
Travis Watkins authored
52  src/main/java/net/minecraft/server/ConsoleLogManager.java
@@ -6,10 +6,10 @@
6 6
 import java.util.logging.Logger;
7 7
 
8 8
 // CraftBukkit start
  9
+import java.io.File;
9 10
 import java.util.logging.Handler;
10 11
 import org.bukkit.craftbukkit.util.ShortConsoleLogFormatter;
11 12
 import org.bukkit.craftbukkit.util.TerminalConsoleHandler;
12  
-
13 13
 // CraftBukkit end
14 14
 
15 15
 public class ConsoleLogManager {
@@ -41,6 +41,56 @@ public static void init(MinecraftServer server) {
41 41
         try {
42 42
             // CraftBukkit start
43 43
             String pattern = (String) server.options.valueOf("log-pattern");
  44
+
  45
+            // We have to parse the pattern ourself so we can create directories as needed (java #6244047)
  46
+            String tmpDir = System.getProperty("java.io.tmpdir");
  47
+            String homeDir = System.getProperty("user.home");
  48
+            if (tmpDir == null) {
  49
+                tmpDir = homeDir;
  50
+            }
  51
+
  52
+            // We only care about parsing for directories, FileHandler can do file names by itself
  53
+            File parent = new File(pattern).getParentFile();
  54
+            String parentPath = parent.getPath();
  55
+            StringBuilder fixedPattern = new StringBuilder();
  56
+
  57
+            int i = 0;
  58
+            while (i < parentPath.length()) {
  59
+                char ch = parentPath.charAt(i);
  60
+                char ch2 = 0;
  61
+                if (i + 1 < parentPath.length()) {
  62
+                    ch2 = Character.toLowerCase(pattern.charAt(i + 1));
  63
+                }
  64
+
  65
+                if (ch == '%') {
  66
+                    if (ch2 == 'h') {
  67
+                        i += 2;
  68
+                        fixedPattern.append(homeDir);
  69
+                        continue;
  70
+                    } else if (ch2 == 't') {
  71
+                        i += 2;
  72
+                        fixedPattern.append(tmpDir);
  73
+                        continue;
  74
+                    } else if (ch2 == '%') {
  75
+                        // Even though we don't care about this we have to skip it to avoid matching %%t
  76
+                        i += 2;
  77
+                        fixedPattern.append("%%");
  78
+                        continue;
  79
+                    } else if (ch2 != 0) {
  80
+                        throw new java.io.IOException("log-pattern can only use %t and %h for directories, got %" + ch2);
  81
+                    }
  82
+                }
  83
+
  84
+                fixedPattern.append(ch);
  85
+                i++;
  86
+            }
  87
+
  88
+            // Try to create needed parent directories
  89
+            parent = new File(fixedPattern.toString());
  90
+            if (parent != null) {
  91
+                parent.mkdirs();
  92
+            }
  93
+
44 94
             int limit = ((Integer) server.options.valueOf("log-limit")).intValue();
45 95
             int count = ((Integer) server.options.valueOf("log-count")).intValue();
46 96
             boolean append = ((Boolean) server.options.valueOf("log-append")).booleanValue();

1 note on commit be7a79c

Andrewkm

This is causing issues with creating server log file.
If one doesnt exist it wont create it and if it does exist it simple wont log...
http://i.imgur.com/aay90.png

Please sign in to comment.
Something went wrong with that request. Please try again.