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 2022/03/18 09:53:01 UTC
[karaf] branch main updated: [KARAF-7389] Prevent two threads (feature installer, CM Event Dispatcher through fileinstall) writing the same config file
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 f3260d5 [KARAF-7389] Prevent two threads (feature installer, CM Event Dispatcher through fileinstall) writing the same config file
new 9c0fcca Merge pull request #1489 from grgrzybek/KARAF-7389
f3260d5 is described below
commit f3260d5ab641cdbf1bbd594875c07d974ed470a0
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Wed Feb 9 11:53:33 2022 +0100
[KARAF-7389] Prevent two threads (feature installer, CM Event Dispatcher through fileinstall) writing the same config file
---
.../karaf/features/internal/service/FeatureConfigInstaller.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
index ba46eb3..40bb666 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
@@ -137,10 +137,10 @@ public class FeatureConfigInstaller {
cfg = createConfiguration(configAdmin, cid);
cfgProps.put(CONFIG_KEY, cid.pid);
properties.put(CONFIG_KEY, cid.pid);
+ cfg.update(cfgProps);
if (storage != null && configCfgStore) {
cfgProps.put(FILEINSTALL_FILE_NAME, cfgFile.getAbsoluteFile().toURI().toString());
}
- cfg.update(cfgProps);
try {
updateStorage(cid, properties, false, jsonFormat);
} catch (Exception e) {
@@ -325,11 +325,13 @@ public class FeatureConfigInstaller {
if (storage != null && configCfgStore) {
File cfgFile = getConfigFile(cid, jsonFormat);
if (!cfgFile.exists()) {
+ File tmpCfgFile = File.createTempFile(cfgFile.getName(), ".tmp", cfgFile.getParentFile());
if (jsonFormat) {
- Configurations.buildWriter().build(new FileWriter(cfgFile)).writeConfiguration(convertToDict(props));
+ Configurations.buildWriter().build(new FileWriter(tmpCfgFile)).writeConfiguration(convertToDict(props));
} else {
- props.save(cfgFile);
+ props.save(tmpCfgFile);
}
+ tmpCfgFile.renameTo(cfgFile);
} else {
updateExistingConfig(props, append, cfgFile, jsonFormat);
}