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:04 UTC
[celix] 02/02: Add initial support for uncompressed bundle.
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;