You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2021/05/24 05:59:29 UTC

[karaf] branch main updated: KARAF-7157 - Editing a factory cfg lacking a FILEINSTALL_FILE_NAME prop. produces a file with incorrect filename

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new 3bd28ac  KARAF-7157 - Editing a factory cfg lacking a FILEINSTALL_FILE_NAME prop. produces a file with incorrect filename
     new 47424a2  Merge pull request #1380 from jassuncao/KARAF-7157
3bd28ac is described below

commit 3bd28ac8812b131c688c565c4dc989bef106a366
Author: exp_jassuncao <jo...@exploitsys.com>
AuthorDate: Sun May 23 18:26:44 2021 +0100

    KARAF-7157 - Editing a factory cfg lacking a FILEINSTALL_FILE_NAME prop.
    produces a file with incorrect filename
    
    When generating a filename for a configuration lacking a
    FILEINSTALL_FILE_NAME property, the type of configuration is taken in
    consideration and a filename following the convention
    <factoryPID>-<identifier>.cfg  will be used for factory configs.
    
    Change-Id: I5bd2012a48bb4d7804199e64f6b387d4201333e1
---
 .../karaf/config/core/impl/ConfigRepositoryImpl.java    | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/config/src/main/java/org/apache/karaf/config/core/impl/ConfigRepositoryImpl.java b/config/src/main/java/org/apache/karaf/config/core/impl/ConfigRepositoryImpl.java
index 84a1d05..c5bfa76 100644
--- a/config/src/main/java/org/apache/karaf/config/core/impl/ConfigRepositoryImpl.java
+++ b/config/src/main/java/org/apache/karaf/config/core/impl/ConfigRepositoryImpl.java
@@ -81,7 +81,7 @@ public class ConfigRepositoryImpl implements ConfigRepository {
                     file = getCfgFileFromProperty(properties.get(FILEINSTALL_FILE_NAME));
                 }
                 if (file == null) {
-                    file = new File(System.getProperty("karaf.etc"), pid + "."  + suffix);
+                    file = generateConfigFilename(cfg, suffix);
                 }
                 props.putAll(properties);
                 props.keySet().retainAll(properties.keySet());
@@ -93,6 +93,21 @@ public class ConfigRepositoryImpl implements ConfigRepository {
             throw new IOException("Error updating config", e);
         }
     }
+    
+    private static File generateConfigFilename(Configuration cfg, String suffix) {
+        final String pid = cfg.getPid();
+        final String factoryPid = cfg.getFactoryPid();
+        String fName;
+        if(factoryPid!=null) {
+            //pid = <factoryPid>.<identifier>
+            String identifier = pid.substring(factoryPid.length()+1);
+            fName = cfg.getFactoryPid() + "-"+identifier+ "."  + suffix;
+        }
+        else {
+            fName = pid + "."  + suffix;
+        }
+        return new File(System.getProperty("karaf.etc"), fName);
+    }
 
     /* (non-Javadoc)
      * @see org.apache.karaf.shell.config.impl.ConfigRepository#delete(java.lang.String)