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

pengzheng pushed a commit to branch feature/556-osgi-uninstall
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/feature/556-osgi-uninstall by 
this push:
     new 2e24b1f6 Avoid unnecessary disk write with an extra disk read.
2e24b1f6 is described below

commit 2e24b1f6325723135a24b4e96f4acb6c25bb1a30
Author: PengZheng <[email protected]>
AuthorDate: Tue May 30 21:11:42 2023 +0800

    Avoid unnecessary disk write with an extra disk read.
---
 libs/framework/src/bundle_archive.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/libs/framework/src/bundle_archive.c 
b/libs/framework/src/bundle_archive.c
index dc6e7c30..aec52ce4 100644
--- a/libs/framework/src/bundle_archive.c
+++ b/libs/framework/src/bundle_archive.c
@@ -60,22 +60,38 @@ struct bundleArchive {
 };
 
 static celix_status_t 
celix_bundleArchive_storeBundleStateProperties(bundle_archive_pt archive) {
-    celix_properties_t* bundleStateProperties = celix_properties_create();
+    bool needUpdate = false;
+    celix_properties_t* bundleStateProperties = NULL;
+    bundleStateProperties = 
celix_properties_load(archive->savedBundleStatePropertiesPath);
+    if (bundleStateProperties == NULL) {
+        bundleStateProperties = celix_properties_create();
+    }
     if (bundleStateProperties == NULL) {
         return CELIX_ENOMEM;
     }
-    celixThreadMutex_lock(&archive->lock);
     //set/update bundle cache state properties
-    celix_properties_setLong(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_BUNDLE_ID_PROPERTY_NAME, archive->id);
-    celix_properties_set(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_LOCATION_PROPERTY_NAME, archive->location);
-    celix_properties_set(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME,
-                         archive->bundleSymbolicName);
-    celix_properties_set(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME, archive->bundleVersion);
+    if (celix_properties_getAsLong(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_BUNDLE_ID_PROPERTY_NAME, 0) != archive->id) {
+        celix_properties_setLong(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_BUNDLE_ID_PROPERTY_NAME, archive->id);
+        needUpdate = true;
+    }
+    if (strcmp(celix_properties_get(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_LOCATION_PROPERTY_NAME, ""), archive->location) != 0) {
+        celix_properties_set(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_LOCATION_PROPERTY_NAME, archive->location);
+        needUpdate = true;
+    }
+    if (strcmp(celix_properties_get(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME, ""), 
archive->bundleSymbolicName) != 0) {
+        celix_properties_set(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME, archive->bundleSymbolicName);
+        needUpdate = true;
+    }
+    if (strcmp(celix_properties_get(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME, ""), archive->bundleVersion) != 0) {
+        celix_properties_set(bundleStateProperties, 
CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME, archive->bundleVersion);
+        needUpdate = true;
+    }
 
     //save bundle cache state properties
-    celix_properties_store(bundleStateProperties, 
archive->savedBundleStatePropertiesPath,
-                           "Bundle State Properties");
-    celixThreadMutex_unlock(&archive->lock);
+    if (needUpdate) {
+        celix_properties_store(bundleStateProperties, 
archive->savedBundleStatePropertiesPath,
+                               "Bundle State Properties");
+    }
     celix_properties_destroy(bundleStateProperties);
     return CELIX_SUCCESS;
 }

Reply via email to