You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pe...@apache.org on 2022/09/01 10:44:32 UTC

[celix] 01/01: Skip bundle extraction when reloading bundle from cache.

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

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

commit 2cb699ac6815317a626422ba10e753c8c7964177
Author: PengZheng <ho...@gmail.com>
AuthorDate: Thu Sep 1 18:44:17 2022 +0800

    Skip bundle extraction when reloading bundle from cache.
---
 libs/framework/include/bundle_revision.h |  5 +++--
 libs/framework/src/bundle_archive.c      |  8 ++++----
 libs/framework/src/bundle_revision.c     | 15 ++++++++-------
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/libs/framework/include/bundle_revision.h b/libs/framework/include/bundle_revision.h
index 2190dc4b..af73f600 100644
--- a/libs/framework/include/bundle_revision.h
+++ b/libs/framework/include/bundle_revision.h
@@ -31,6 +31,7 @@
 #define BUNDLE_REVISION_H_
 
 #include <stdio.h>
+#include <stdbool.h>
 
 #include "celix_types.h"
 
@@ -56,11 +57,11 @@ extern "C" {
  * The location parameter is used to identify the bundle, in case of an update or download, the inputFile
  *  parameter can be used to point to the actual data. In the OSGi specification this is the inputstream.
  *
- * @param pool The pool on which this revision has to be allocated.
  * @param root The root for this revision in which the bundle is extracted and state is stored.
  * @param location The location associated with the revision
  * @param revisionNr The number of the revision
  * @param inputFile The (optional) location of the file to use as input for this revision
+ * @param cache Whether this revision represents a cache entry, in which case bundle extraction is skipped.
  * @param[out] bundle_revision The output parameter for the created revision.
  *
  * @return Status code indication failure or success:
@@ -68,7 +69,7 @@ extern "C" {
  * 		- CELIX_ENOMEM If allocating memory for <code>bundle_revision</code> failed.
  */
 celix_status_t bundleRevision_create(const char *root, const char *location, long revisionNr, const char *inputFile,
-                                     bundle_revision_pt *bundle_revision);
+                                     bool cache, bundle_revision_pt *bundle_revision);
 
 celix_status_t bundleRevision_destroy(bundle_revision_pt revision);
 
diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/bundle_archive.c
index 80d53607..d768418e 100644
--- a/libs/framework/src/bundle_archive.c
+++ b/libs/framework/src/bundle_archive.c
@@ -51,7 +51,7 @@ static celix_status_t bundleArchive_initialize(bundle_archive_pt archive);
 
 static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, const char * directory);
 
-static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt archive, const char *location, const char *inputFile, long revNr, bundle_revision_pt *bundle_revision);
+static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt archive, const char *location, const char *inputFile, long revNr, bundle_revision_pt *bundle_revision, bool isReload);
 static celix_status_t bundleArchive_reviseInternal(bundle_archive_pt archive, bool isReload, long revNr, const char * location, const char *inputFile);
 
 static celix_status_t bundleArchive_readLastModified(bundle_archive_pt archive, time_t *time);
@@ -567,7 +567,7 @@ static celix_status_t bundleArchive_reviseInternal(bundle_archive_pt archive, bo
 		location = "inputstream:";
 	}
 
-	status = bundleArchive_createRevisionFromLocation(archive, location, inputFile, revNr, &revision);
+	status = bundleArchive_createRevisionFromLocation(archive, location, inputFile, revNr, &revision, isReload);
 
 	if (status == CELIX_SUCCESS) {
 		if (!isReload) {
@@ -587,7 +587,7 @@ celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool *rol
 	return CELIX_SUCCESS;
 }
 
-static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt archive, const char *location, const char *inputFile, long revNr, bundle_revision_pt *bundle_revision) {
+static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt archive, const char *location, const char *inputFile, long revNr, bundle_revision_pt *bundle_revision, bool isReload) {
 	celix_status_t status = CELIX_SUCCESS;
 	char root[256];
 	long refreshCount;
@@ -597,7 +597,7 @@ static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt
 		bundle_revision_pt revision = NULL;
 
 		sprintf(root, "%s/version%ld.%ld", archive->archiveRoot, refreshCount, revNr);
-		status = bundleRevision_create(root, location, revNr, inputFile, &revision);
+		status = bundleRevision_create(root, location, revNr, inputFile, isReload, &revision);
 
 		if (status == CELIX_SUCCESS) {
 			*bundle_revision = revision;
diff --git a/libs/framework/src/bundle_revision.c b/libs/framework/src/bundle_revision.c
index dd988e2f..286a2916 100644
--- a/libs/framework/src/bundle_revision.c
+++ b/libs/framework/src/bundle_revision.c
@@ -27,7 +27,7 @@
 
 #include "bundle_revision_private.h"
 
-celix_status_t bundleRevision_create(const char *root, const char *location, long revisionNr, const char *inputFile, bundle_revision_pt *bundle_revision) {
+celix_status_t bundleRevision_create(const char *root, const char *location, long revisionNr, const char *inputFile, bool cache, bundle_revision_pt *bundle_revision) {
     celix_status_t status = CELIX_SUCCESS;
 	bundle_revision_pt revision = NULL;
 
@@ -40,13 +40,14 @@ celix_status_t bundleRevision_create(const char *root, const char *location, lon
             free(revision);
             status = CELIX_FILE_IO_EXCEPTION;
         } else {
-            if (inputFile != NULL) {
-                status = extractBundle(inputFile, root);
-            } else if (strcmp(location, "inputstream:") != 0) {
-            	// If location != inputstream, extract it, else ignore it and assume this is a cache entry.
-                status = extractBundle(location, root);
+            if (!cache) {
+                if (inputFile != NULL) {
+                    status = extractBundle(inputFile, root);
+                } else if (strcmp(location, "inputstream:") != 0) {
+                    // If location != inputstream, extract it, else ignore it and assume this is a cache entry.
+                    status = extractBundle(location, root);
+                }
             }
-
             status = CELIX_DO_IF(status, arrayList_create(&(revision->libraryHandles)));
             if (status == CELIX_SUCCESS) {
                 revision->revisionNr = revisionNr;