You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2011/03/14 11:15:26 UTC

svn commit: r1081304 - /karaf/trunk/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java

Author: gnodet
Date: Mon Mar 14 10:15:25 2011
New Revision: 1081304

URL: http://svn.apache.org/viewvc?rev=1081304&view=rev
Log:
[KARAF-509] The config:update command does not save factory configurations to the correct file

Modified:
    karaf/trunk/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java

Modified: karaf/trunk/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java?rev=1081304&r1=1081303&r2=1081304&view=diff
==============================================================================
--- karaf/trunk/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java (original)
+++ karaf/trunk/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java Mon Mar 14 10:15:25 2011
@@ -20,15 +20,18 @@ import java.io.File;
 import java.util.Dictionary;
 import java.util.Enumeration;
 
+import org.apache.felix.gogo.commands.Command;
 import org.apache.felix.gogo.commands.Option;
 import org.apache.felix.utils.properties.Properties;
+import org.osgi.framework.Constants;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
-import org.apache.felix.gogo.commands.Command;
 
 @Command(scope = "config", name = "update", description = "Saves and propagates changes from the configuration being edited.")
 public class UpdateCommand extends ConfigCommandSupport {
 
+    private final String FELIX_FILEINSTALL_FILENAME = "felix.fileinstall.filename";
+
     @Option(name = "-b", aliases = { "--bypass-storage" }, multiValued = false, required = false, description = "Do not store the configuration in a properties file, but feed it directly to ConfigAdmin")
     private boolean bypassStorage;
 
@@ -48,24 +51,34 @@ public class UpdateCommand extends Confi
             System.err.println("No configuration is being edited. Run the edit command first");
         } else if (!bypassStorage && storage != null) {
         	String pid = (String) this.session.get(PROPERTY_CONFIG_PID);
-        	File storageFile = new File(storage, pid + ".cfg");
+            File storageFile = new File(storage, pid + ".cfg");
+            Configuration cfg = admin.getConfiguration(pid, null);
+            if (cfg != null) {
+                Object val = cfg.getProperties().get(FELIX_FILEINSTALL_FILENAME);
+                if (val instanceof String) {
+                    if (((String) val).startsWith("file:")) {
+                        val = ((String) val).substring("file:".length());
+                    }
+                    storageFile = new File((String) val);
+                }
+            }
             Properties p = new Properties(storageFile);
             for (Enumeration keys = props.keys(); keys.hasMoreElements();) {
                 Object key = keys.nextElement();
-                if (!"service.pid".equals(key) && !"felix.fileinstall.filename".equals(key)) {
+                if (!Constants.SERVICE_PID.equals(key)
+                        && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
+                        && !FELIX_FILEINSTALL_FILENAME.equals(key)) {
                     p.put((String) key, (String) props.get(key));
                 }
             }
             storage.mkdirs();
             p.save();
-            this.session.put(PROPERTY_CONFIG_PID, null);
-            this.session.put(PROPERTY_CONFIG_PROPS, null);
         } else {
             String pid = (String) this.session.get(PROPERTY_CONFIG_PID);
             Configuration cfg = admin.getConfiguration(pid, null);
             cfg.update(props);
-            this.session.put(PROPERTY_CONFIG_PID, null);
-            this.session.put(PROPERTY_CONFIG_PROPS, null);
         }
+        this.session.put(PROPERTY_CONFIG_PID, null);
+        this.session.put(PROPERTY_CONFIG_PROPS, null);
     }
 }