From b6605787436695a7a43c91ed774449857f39cf03 Mon Sep 17 00:00:00 2001 From: PengZheng Date: Fri, 22 Sep 2023 17:19:13 +0800 Subject: [PATCH] [#643] Create destination directory before performing decompression. Bundle produces by zip does not necessarily begin with META-INF. --- libs/utils/gtest/src/FileUtilsTestSuite.cc | 9 ++++++++- libs/utils/src/celix_file_utils.c | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/utils/gtest/src/FileUtilsTestSuite.cc b/libs/utils/gtest/src/FileUtilsTestSuite.cc index 0b4755a95..6ff80d79c 100644 --- a/libs/utils/gtest/src/FileUtilsTestSuite.cc +++ b/libs/utils/gtest/src/FileUtilsTestSuite.cc @@ -189,9 +189,16 @@ TEST_F(FileUtilsTestSuite, ExtractZipFileTest) { EXPECT_EQ(celix_properties_getAsLong(props, "level", 0), 2); celix_properties_destroy(props); + //Given a test zip file, extract to file is a error + const char* error = nullptr; + status = celix_utils_extractZipFile(TEST_ZIP_LOCATION, file1, &error); + EXPECT_NE(status, CELIX_SUCCESS); + EXPECT_NE(error, nullptr); + + //Given a incorrect path extractZipFile returns a error const char* invalidPath = "does-not-exists.zip"; - const char* error = nullptr; + error = nullptr; EXPECT_FALSE(celix_utils_fileExists(invalidPath)); status = celix_utils_extractZipFile(invalidPath, extractLocation, &error); EXPECT_NE(status, CELIX_SUCCESS); diff --git a/libs/utils/src/celix_file_utils.c b/libs/utils/src/celix_file_utils.c index dcfd6b70c..692be8d61 100644 --- a/libs/utils/src/celix_file_utils.c +++ b/libs/utils/src/celix_file_utils.c @@ -214,6 +214,11 @@ static celix_status_t celix_utils_extractZipInternal(zip_t *zip, const char* ext char buf[5120]; size_t bufSize = 5112; + status = celix_utils_createDirectory(extractToDir, false, errorOut); + if (status != CELIX_SUCCESS) { + return status; + } + for (zip_int64_t i = 0; status == CELIX_SUCCESS && i < nrOfEntries; ++i) { zip_stat_t st; if(zip_stat_index(zip, i, 0, &st) == -1) {