felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1693428 - in /felix/trunk/configadmin/src: main/java/org/apache/felix/cm/file/FilePersistenceManager.java main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
Date Thu, 30 Jul 2015 14:07:38 GMT
Author: cziegeler
Date: Thu Jul 30 14:07:38 2015
New Revision: 1693428

URL: http://svn.apache.org/r1693428
Log:
FELIX-4945 : Escaped folder names makes ConfigAdmin incompatible and factory configs not always
work. Apply patch from Balazs Zsoldos

Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java?rev=1693428&r1=1693427&r2=1693428&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
Thu Jul 30 14:07:38 2015
@@ -144,16 +144,6 @@ public class FilePersistenceManager impl
      */
     private final boolean isWin;
 
-    /**
-     * A set of three character names (prefixes) considered reserved
-     * on Windows platform systems. This set consists of names such as
-     * LPT, CON, COM, etc., which cause weird behaviour on Windows systems
-     * if used as prefixes on path segments. See .
-     *
-     * @see <a href="https://issues.apache.org/jira/browse/FELIX-4302">FELIX-4302</a>
-     */
-    private final Set winDevNames;
-
     // sets up this class defining the set of valid characters in path
     // set getFile(String) for details.
     static
@@ -187,21 +177,37 @@ public class FilePersistenceManager impl
         // "Windows" hence we assume a Windows platform in thus case.
         final String osName = System.getProperty( "os.name" );
         isWin = osName != null && osName.startsWith( "Windows" );
-        if ( isWin )
-        {
-            winDevNames = new HashSet();
-            winDevNames.add( "CON" ); // keyboard and display
-            winDevNames.add( "PRN" ); // system list; generally par. port
-            winDevNames.add( "AUX" ); // auxiliary; generally ser. port
-            winDevNames.add( "CLO" ); // CLOCK$; system real time clock
-            winDevNames.add( "NUL" ); // Bit-bucket
-            winDevNames.add( "COM" ); // COM1..COMn; serial ports
-            winDevNames.add( "LPT" ); // LPT1..LPTn; parallel ports
+    }
+    
+    private static boolean equalsNameWithPrefixPlusOneDigit( String name, String prefix)
{
+        if ( name.length() != prefix.length() + 1 ) {
+            return false;
         }
-        else
-        {
-            winDevNames = null;
+        if ( !name.startsWith(prefix) ) {
+            return false;
+        }
+        char charAfterPrefix = name.charAt( prefix.length() );
+        return charAfterPrefix > '0' && charAfterPrefix < '9';
+    }
+
+    private static boolean isWinReservedName(String name) {
+        String upperCaseName = name.toUpperCase();
+        if ( "CON".equals( upperCaseName ) ) {
+            return true;
+        } else if ( "PRN".equals( upperCaseName ) ){
+            return true;
+        } else if ( "AUX".equals( upperCaseName ) ){
+            return true;
+        } else if ( "CLOCK$".equals( upperCaseName ) ){
+            return true;
+        } else if ( "NUL".equals( upperCaseName ) ){
+            return true;
+        } else if ( equalsNameWithPrefixPlusOneDigit( upperCaseName, "COM") ) {
+            return true;
+        } else if ( equalsNameWithPrefixPlusOneDigit( upperCaseName, "LPT") ){
+            return true;
         }
+        return false;
     }
 
 
@@ -403,7 +409,7 @@ public class FilePersistenceManager impl
             while ( segments.hasMoreTokens() )
             {
                 final String segment = segments.nextToken();
-                if ( segment.length() >= 3 && winDevNames.contains( segment.substring(
0, 3 ).toUpperCase() ) )
+                if ( isWinReservedName(segment) )
                 {
                     appendEncoded( pidBuffer, segment.charAt( 0 ) );
                     pidBuffer.append( segment.substring( 1 ) );

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java?rev=1693428&r1=1693427&r2=1693428&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
Thu Jul 30 14:07:38 2015
@@ -20,6 +20,7 @@ package org.apache.felix.cm.impl;
 
 
 import java.io.IOException;
+
 import org.osgi.framework.Bundle;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
@@ -38,10 +39,10 @@ public class ConfigurationAdminImpl impl
 {
 
     // The configuration manager to which most of the tasks are delegated
-    private ConfigurationManager configurationManager;
+    private volatile ConfigurationManager configurationManager;
 
     // The bundle for which this instance has been created
-    private Bundle bundle;
+    private volatile Bundle bundle;
 
 
     ConfigurationAdminImpl( ConfigurationManager configurationManager, Bundle bundle )

Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java?rev=1693428&r1=1693427&r2=1693428&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
(original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
Thu Jul 30 14:07:38 2015
@@ -102,7 +102,7 @@ public class FilePersistenceManagerTest
             assertEquals("%0043ON", winFpm.encodePid( "CON" ));
             assertEquals("%0050RN", winFpm.encodePid( "PRN" ));
             assertEquals("%0041UX", winFpm.encodePid( "AUX" ));
-            assertEquals("%0043LOCK%0024", winFpm.encodePid( "CLOCK$" ));
+            assertEquals("CLOCK%0024", winFpm.encodePid( "CLOCK$" ));
             assertEquals("%004eUL", winFpm.encodePid( "NUL" ));
             assertEquals("%0043OM6", winFpm.encodePid( "COM6" ));
         } finally {



Mime
View raw message