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 2023/06/26 13:42:02 UTC
[celix] branch feature/522-support-uncompressed-bundle updated (4863418f -> 9eee2ff1)
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a change to branch feature/522-support-uncompressed-bundle
in repository https://gitbox.apache.org/repos/asf/celix.git
from 4863418f Remove unnecessary directory creation in `celix_bundleArchive_createCacheDirectory`.
new 60627426 Use the last modification time of the bundle archive cache dir rather than that of the manifest.
new 9eee2ff1 Add initial support for uncompressed bundle.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../BundleArchiveWithErrorInjectionTestSuite.cc | 4 +--
.../gtest/src/CelixFrameworkUtilsTestSuite.cc | 32 ++++++++++++++++++----
libs/framework/include_deprecated/bundle_archive.h | 2 +-
libs/framework/src/bundle_archive.c | 17 ++----------
libs/framework/src/bundle_archive_private.h | 5 ----
libs/framework/src/celix_framework_utils.c | 22 +++++++++++----
6 files changed, 47 insertions(+), 35 deletions(-)
[celix] 01/02: Use the last modification time of the bundle archive cache dir rather than that of the manifest.
Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/522-support-uncompressed-bundle
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 60627426306a3f90a4c4102904260463e6721f0e
Author: PengZheng <ho...@gmail.com>
AuthorDate: Mon Jun 26 17:28:56 2023 +0800
Use the last modification time of the bundle archive cache dir rather than that of the manifest.
Note that for and uncompressed bundle, these two modification timestamps might be different, which may lead to superfluous disk write when uncompressed bundle is supported.
---
.../src/BundleArchiveWithErrorInjectionTestSuite.cc | 4 ++--
libs/framework/include_deprecated/bundle_archive.h | 2 +-
libs/framework/src/bundle_archive.c | 17 ++---------------
libs/framework/src/bundle_archive_private.h | 5 -----
4 files changed, 5 insertions(+), 23 deletions(-)
diff --git a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc
index 942b8e45..4861ea44 100644
--- a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc
+++ b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc
@@ -185,8 +185,8 @@ TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) {
bundle_archive_t* archive = nullptr;
// archive directory creation failures not covered by other tests
- celix_ei_expect_celix_utils_writeOrCreateString((void*)celix_bundleArchive_getLastModifiedInternal, 0, nullptr);
- EXPECT_EQ(CELIX_ENOMEM,
+ celix_ei_expect_celix_utils_getLastModified((void*)celix_bundleArchive_create, 2, CELIX_FILE_IO_EXCEPTION);
+ EXPECT_EQ(CELIX_FILE_IO_EXCEPTION,
celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
EXPECT_EQ(nullptr, archive);
EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT));
diff --git a/libs/framework/include_deprecated/bundle_archive.h b/libs/framework/include_deprecated/bundle_archive.h
index daa9b0aa..d53518a1 100644
--- a/libs/framework/include_deprecated/bundle_archive.h
+++ b/libs/framework/include_deprecated/bundle_archive.h
@@ -90,7 +90,7 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getPersistentStat
/**
* @brief Return the last modified time of the bundle archive.
*
- * The last modified time is based on the last modified time of the bundle archives MANIFEST.MF file.
+ * The last modified time is based on the last modified time of the bundle archive cache directory.
*
* If the bundle archive cache directory does not exist, lastModified will be set to 0.
*
diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/bundle_archive.c
index e977fe6f..9bb0b0fd 100644
--- a/libs/framework/src/bundle_archive.c
+++ b/libs/framework/src/bundle_archive.c
@@ -103,7 +103,7 @@ celix_bundleArchive_extractBundle(bundle_archive_t* archive, const char* bundleU
//get revision mod time;
struct timespec revisionMod;
- status = celix_bundleArchive_getLastModifiedInternal(archive, &revisionMod);
+ status = celix_utils_getLastModified(archive->resourceCacheRoot, &revisionMod);
if (status != CELIX_SUCCESS && errno != ENOENT) {
fw_logCode(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Failed to get last modified time for bundle archive revision directory '%s'", archive->resourceCacheRoot);
return status;
@@ -396,23 +396,10 @@ celix_status_t bundleArchive_getLastModified(bundle_archive_pt archive, time_t*
}
//LCOV_EXCL_STOP
-celix_status_t celix_bundleArchive_getLastModifiedInternal(bundle_archive_pt archive, struct timespec* lastModified) {
- // precondition: archive->lock is locked
- celix_status_t status = CELIX_SUCCESS;
- char manifestPathBuffer[CELIX_DEFAULT_STRING_CREATE_BUFFER_SIZE];
- char* manifestPath = celix_utils_writeOrCreateString(manifestPathBuffer, sizeof(manifestPathBuffer), "%s/%s", archive->resourceCacheRoot, CELIX_BUNDLE_MANIFEST_REL_PATH);
- if (manifestPath == NULL) {
- status = CELIX_ENOMEM;
- }
- status = CELIX_DO_IF(status, celix_utils_getLastModified(manifestPath, lastModified));
- celix_utils_freeStringIfNotEqual(manifestPathBuffer, manifestPath);
- return status;
-}
-
celix_status_t celix_bundleArchive_getLastModified(bundle_archive_pt archive, struct timespec* lastModified) {
celix_status_t status;
celixThreadMutex_lock(&archive->lock);
- status = celix_bundleArchive_getLastModifiedInternal(archive, lastModified);
+ status = celix_utils_getLastModified(archive->resourceCacheRoot, lastModified);
celixThreadMutex_unlock(&archive->lock);
return status;
}
diff --git a/libs/framework/src/bundle_archive_private.h b/libs/framework/src/bundle_archive_private.h
index 379213ea..b6a837d9 100644
--- a/libs/framework/src/bundle_archive_private.h
+++ b/libs/framework/src/bundle_archive_private.h
@@ -75,11 +75,6 @@ const char* celix_bundleArchive_getPersistentStoreRoot(bundle_archive_t *archive
*/
const char* celix_bundleArchive_getCurrentRevisionRoot(bundle_archive_pt archive);
-/**
- * Return the last modified time of the bundle archive.
- */
-celix_status_t celix_bundleArchive_getLastModifiedInternal(bundle_archive_pt archive, struct timespec* lastModified);
-
#ifdef __cplusplus
}
#endif
[celix] 02/02: Add initial support for uncompressed bundle.
Posted by pe...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/522-support-uncompressed-bundle
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 9eee2ff16fd12cbc1d5a78154323185c6f926839
Author: PengZheng <ho...@gmail.com>
AuthorDate: Mon Jun 26 21:41:47 2023 +0800
Add initial support for uncompressed bundle.
---
.../gtest/src/CelixFrameworkUtilsTestSuite.cc | 32 ++++++++++++++++++----
libs/framework/src/celix_framework_utils.c | 22 +++++++++++----
2 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc b/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc
index 1dc59cef..667ff309 100644
--- a/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc
+++ b/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc
@@ -20,12 +20,16 @@
#include <gtest/gtest.h>
#include <dirent.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "celix/FrameworkFactory.h"
#include "celix/FrameworkUtils.h"
-#include "celix_framework_utils_private.h"
#include "celix_file_utils.h"
+#include "celix_framework_utils_private.h"
/**
* Tests for the C and C++ framework utils functions which can be found in
@@ -84,11 +88,6 @@ TEST_F(CelixFrameworkUtilsTestSuite, ExtractBundlePathTest) {
status = celix_framework_utils_extractBundle(framework->getCFramework(), "non-existing.zip", testExtractDir); //note nullptr framwork is allowed, fallback to global logger.
EXPECT_NE(status, CELIX_SUCCESS);
-
- //invalid bundle path -> no extraction
- status = celix_framework_utils_extractBundle(framework->getCFramework(), "./", testExtractDir); //note nullptr framwork is allowed, fallback to global logger.
- EXPECT_NE(status, CELIX_SUCCESS);
-
//invalid url prefix -> no extraction
std::string path = std::string{"bla://"} + SIMPLE_TEST_BUNDLE1_LOCATION;
status = celix_framework_utils_extractBundle(framework->getCFramework(), path.c_str(), testExtractDir);
@@ -118,6 +117,27 @@ TEST_F(CelixFrameworkUtilsTestSuite, ExtractBundlePathTest) {
celix_utils_deleteDirectory(testExtractDir, nullptr);
}
+TEST_F(CelixFrameworkUtilsTestSuite, ExtractUncompressedBundleTest) {
+ const char* testExtractDir = "extractBundleTestDir";
+ const char* testLinkDir = "linkBundleTestDir";
+ celix_utils_deleteDirectory(testExtractDir, nullptr);
+ celix_utils_deleteDirectory(testLinkDir, nullptr);
+ EXPECT_EQ(CELIX_SUCCESS, celix_utils_extractZipFile(SIMPLE_TEST_BUNDLE1_LOCATION, testExtractDir, nullptr));
+
+ //valid bundle path -> install a symbolic link
+ auto status = celix_framework_utils_extractBundle(framework->getCFramework(), testExtractDir, testLinkDir);
+ EXPECT_EQ(status, CELIX_SUCCESS);
+ struct stat st1, st2, st3;
+ EXPECT_EQ(0, lstat(testLinkDir, &st1));
+ EXPECT_TRUE(S_ISLNK(st1.st_mode));
+ EXPECT_EQ(0, stat(testLinkDir, &st2));
+ EXPECT_EQ(0, stat(testExtractDir, &st3));
+ EXPECT_EQ(0, memcmp(&st2, &st3, sizeof(struct stat)));
+
+ celix_utils_deleteDirectory(testExtractDir, nullptr);
+ celix_utils_deleteDirectory(testLinkDir, nullptr);
+}
+
TEST_F(CelixFrameworkUtilsTestSuite, ExtractEmbeddedBundleTest) {
const char* testExtractDir = "extractEmbeddedBundleTestDir";
celix_utils_deleteDirectory(testExtractDir, nullptr);
diff --git a/libs/framework/src/celix_framework_utils.c b/libs/framework/src/celix_framework_utils.c
index 8f288227..18f1d0c8 100644
--- a/libs/framework/src/celix_framework_utils.c
+++ b/libs/framework/src/celix_framework_utils.c
@@ -20,20 +20,21 @@
#include "celix_framework_utils.h"
#include "celix_framework_utils_private.h"
+#include <assert.h>
+#include <dlfcn.h>
#include <errno.h>
-#include <string.h>
#include <stdio.h>
#include <stdlib.h>
-#include <dlfcn.h>
-#include <assert.h>
+#include <string.h>
+#include <unistd.h>
#include "bundle_archive.h"
+#include "celix_bundle_context.h"
#include "celix_constants.h"
+#include "celix_file_utils.h"
#include "celix_log.h"
#include "celix_properties.h"
-#include "celix_file_utils.h"
#include "celix_utils.h"
-#include "celix_bundle_context.h"
#include "framework_private.h"
#define FILE_URL_SCHEME "file://"
@@ -196,7 +197,16 @@ static celix_status_t celix_framework_utils_extractBundlePath(celix_framework_t
//other errors should be caught by celix_framework_utils_isBundleUrlValid
return CELIX_ENOMEM;
}
- celix_status_t status = celix_utils_extractZipFile(resolvedPath, extractPath, &err);
+ celix_status_t status = CELIX_SUCCESS;
+ if (celix_utils_directoryExists(resolvedPath)) {
+ //TODO: add tests
+ char *abs = realpath(resolvedPath, NULL);
+ assert(abs != NULL);
+ symlink(abs, extractPath);
+ free(abs);
+ } else {
+ status = celix_utils_extractZipFile(resolvedPath, extractPath, &err);
+ }
framework_logIfError(fw->logger, status, err, "Could not extract bundle zip file `%s` to `%s`", resolvedPath, extractPath);
celix_utils_freeStringIfNotEqual(buffer, resolvedPath);
return status;