harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r422821 - /incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
Date Mon, 17 Jul 2006 19:48:53 GMT
Author: geirm
Date: Mon Jul 17 12:48:53 2006
New Revision: 422821

URL: http://svn.apache.org/viewvc?rev=422821&view=rev
Log:
cheap fix to solve the problem of there not being a
file separator on temp or user home


Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java?rev=422821&r1=422820&r2=422821&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
Mon Jul 17 12:48:53 2006
@@ -272,20 +272,34 @@
                     e1, ErrorManager.OPEN_FAILURE);
         }
         setOutputStream(output);
-
     }
 
-    //apply settings, parse pattern and open files
+    /**
+     *  Transform the pattern to the valid file name, replacing
+     *  any patterns, and applying generation and uniqueID if
+     *  present
+     *
+     *  @param gen generation of this file
+     *  @param uniqueID distinguishing id of this file
+     *  @return transformed filename ready for use
+     */
     private String parseFileName(int gen, int uniqueID) {
         int cur = 0;
         int next = 0;
         boolean hasUniqueID = false;
         boolean hasGeneration = false;
-        //TODO privilege code?
+
+        //TODO privilege code? 
+
         String tempPath = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
+        boolean tempPathHasSepEnd = (tempPath == null ? false : tempPath.endsWith(File.separator));
+
         String homePath = System.getProperty("user.home"); //$NON-NLS-1$
+        boolean homePathHasSepEnd = (homePath == null ? false : homePath.endsWith(File.separator));
+
         StringBuffer sb = new StringBuffer();
         pattern = pattern.replace('/', File.separatorChar);
+
         char[] value = pattern.toCharArray();
         while ((next = pattern.indexOf('%', cur)) >= 0) {
             if (++next < pattern.length()) {
@@ -299,10 +313,20 @@
                     hasUniqueID = true;
                     break;
                 case 't':
+                    /*
+                     *  we should probably try to do somethig cute here like
+                     *  lookahead for adjacent '/'
+                     */
                     sb.append(value, cur, next - cur - 1).append(tempPath);
+                    if (!tempPathHasSepEnd) {
+                        sb.append(File.separator);
+                    }
                     break;
                 case 'h':
                     sb.append(value, cur, next - cur - 1).append(homePath);
+                    if (!homePathHasSepEnd){
+                        sb.append(File.separator);
+                    }
                     break;
                 case '%':
                     sb.append(value, cur, next - cur - 1).append('%');
@@ -312,16 +336,20 @@
                 }
                 cur = ++next;
             } else {
-
+                // fail silently
             }
         }
+
         sb.append(value, cur, value.length - cur);
+
         if (!hasGeneration && count > 1) {
             sb.append(".").append(gen); //$NON-NLS-1$
         }
+
         if (!hasUniqueID && uniqueID > 0) {
             sb.append(".").append(uniqueID); //$NON-NLS-1$
         }
+
         return sb.toString();
     }
 



Mime
View raw message