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

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


The following commit(s) were added to refs/heads/feature/refactor_bundle_cache 
by this push:
     new 113930cb Minor improvement of bundleRevision.
113930cb is described below

commit 113930cb0927f7360c579feb20005bb03b097cb1
Author: PengZheng <[email protected]>
AuthorDate: Mon Mar 20 14:47:56 2023 +0800

    Minor improvement of bundleRevision.
---
 .../BundleArchiveWithErrorInjectionTestSuite.cc    |  3 ++
 libs/framework/src/bundle_revision.c               | 32 ++++++++--------------
 libs/framework/src/bundle_revision_private.h       |  2 --
 3 files changed, 15 insertions(+), 22 deletions(-)

diff --git 
a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc 
b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc
index e4bb3b1c..d08a6364 100644
--- a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc
+++ b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc
@@ -94,6 +94,9 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, 
BundleArchiveCreatedFailedTest)
     //Given a mocked celix_utils_strdup which returns NULL from a call from 
bundleRevision_create
     celix_ei_expect_celix_utils_strdup((void*)bundleRevision_create, 0, 
nullptr);
     installBundleAndExpectFailure();
+
+    celix_ei_expect_celix_utils_strdup((void*)bundleRevision_create, 0, 
nullptr, 2);
+    installBundleAndExpectFailure();
 }
 
 TEST_F(BundleArchiveWithErrorInjectionTestSuite, 
BundleArchiveCreateCacheDirectoryFailedTest) {
diff --git a/libs/framework/src/bundle_revision.c 
b/libs/framework/src/bundle_revision.c
index d7e6850a..e8b189a5 100644
--- a/libs/framework/src/bundle_revision.c
+++ b/libs/framework/src/bundle_revision.c
@@ -25,39 +25,32 @@
 
 celix_status_t bundleRevision_create(celix_framework_t* fw, const char *root, 
const char *location, long revisionNr, manifest_pt manifest, bundle_revision_pt 
*bundle_revision) {
     celix_status_t status = CELIX_SUCCESS;
-       bundle_revision_pt revision = calloc(1, sizeof(*revision));
+    bundle_revision_pt revision = calloc(1, sizeof(*revision));
     if (revision != NULL) {
         revision->fw = fw;
-        revision->libraryHandles = celix_arrayList_create();
         revision->revisionNr = revisionNr;
+        if (root != NULL) {
+            revision->root = celix_utils_strdup(root);
+        }
+        if (location != NULL) {
+            revision->location = celix_utils_strdup(location);
+        }
         revision->manifest = manifest;
     }
 
-    if (revision == NULL || revision->libraryHandles == NULL) {
+    if (revision == NULL || (root != NULL && revision->root == NULL) || 
(location != NULL && revision->location == NULL)) {
         status = CELIX_ENOMEM;
         fw_logCode(fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create 
bundle revision, out of memory");
-        manifest_destroy(manifest);
         if (revision != NULL) {
-            revision->manifest = NULL;
             bundleRevision_destroy(revision);
+        } else {
+            manifest_destroy(manifest);
         }
         return status;
     }
 
-    bool isSystemRevision = root == NULL && location == NULL;
-    if (!isSystemRevision) {
-        revision->location = celix_utils_strdup(location);
-        revision->root = celix_utils_strdup(root);
-        if (revision->location == NULL || revision->root == NULL) {
-            status = CELIX_ENOMEM;
-            fw_logCode(fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot 
create bundle revision, out of memory");
-            bundleRevision_destroy(revision);
-            return status;
-        }
-    }
-
     *bundle_revision = revision;
-       return status;
+    return status;
 }
 
 bundle_revision_t* bundleRevision_revise(const bundle_revision_t* rev, const 
char* updatedBundleUrl) {
@@ -69,13 +62,12 @@ bundle_revision_t* bundleRevision_revise(const 
bundle_revision_t* rev, const cha
 
 celix_status_t bundleRevision_destroy(bundle_revision_pt revision) {
     if (revision != NULL) {
-        celix_arrayList_destroy(revision->libraryHandles);
         manifest_destroy(revision->manifest);
         free(revision->root);
         free(revision->location);
         free(revision);
     }
-       return CELIX_SUCCESS;
+    return CELIX_SUCCESS;
 }
 
 celix_status_t bundleRevision_getNumber(const bundle_revision_t* revision, 
long *revisionNr) {
diff --git a/libs/framework/src/bundle_revision_private.h 
b/libs/framework/src/bundle_revision_private.h
index 94a30ed9..67a2e3df 100644
--- a/libs/framework/src/bundle_revision_private.h
+++ b/libs/framework/src/bundle_revision_private.h
@@ -44,8 +44,6 @@ struct bundleRevision {
     char *root;
     char *location;
     manifest_pt manifest;
-
-    celix_array_list_t* libraryHandles; //deprecated, moved to module
 };
 
 /**

Reply via email to