FELIX-4945 : Escaped folder names makes ConfigAdmin incompatible and factory configs not always work. Apply patch from Balazs Zsoldos
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1693428 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java b/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
index 5cd224c..dc153a4 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
@@ -144,16 +144,6 @@
*/
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 @@
// "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 @@
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 ) );
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
index 13fadcd..411d316 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminImpl.java
@@ -20,6 +20,7 @@
import java.io.IOException;
+
import org.osgi.framework.Bundle;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
@@ -38,10 +39,10 @@
{
// 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 )
diff --git a/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java b/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
index ad41462..cf52dd6 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
@@ -102,7 +102,7 @@
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 {