diff --git a/adapter/ohos/PackageUtil.java b/adapter/ohos/PackageUtil.java index 26335ccc81b707bc6d3356386ebc6686a4169c08..3039c560cef9aea06b8b7856d041a86588ca7463 100644 --- a/adapter/ohos/PackageUtil.java +++ b/adapter/ohos/PackageUtil.java @@ -184,7 +184,7 @@ public class PackageUtil { } moduleJsonInfo.setGenerateBuildHash( appObject.getBooleanValue(Constants.GENERATE_BUILD_HASH) || - moduleObject.getBooleanValue(Constants.GENERATE_BUILD_HASH)); + moduleObject.getBooleanValue(Constants.GENERATE_BUILD_HASH)); moduleJsonInfo.setCompressNativeLibs( moduleObject.getBooleanValue(Constants.COMPRESS_NATIVE_LIBS)); String moduleType = moduleObject.getString(Constants.MODULE_TYPE); @@ -239,7 +239,7 @@ public class PackageUtil { return null; } try (ZipFile zipFile = new ZipFile(zipPath.toFile()); - ByteArrayOutputStream output = new ByteArrayOutputStream()) { + ByteArrayOutputStream output = new ByteArrayOutputStream()) { ZipArchiveEntry zipEntry = zipFile.getEntry(entryName); if (zipEntry != null) { IOUtils.copy(zipFile.getInputStream(zipEntry), output); @@ -763,6 +763,11 @@ public class PackageUtil { return Files.isRegularFile(path) && path.getFileName().toString().endsWith(suffix); } + private static boolean isFileMatch(String filePath, String matchFileName) { + Path path = Paths.get(filePath); + return Files.isRegularFile(path) && path.getFileName().toString().equals(matchFileName); + } + private static boolean isDirValid(String filePath) { return Files.isDirectory(Paths.get(filePath)); } @@ -807,16 +812,6 @@ public class PackageUtil { LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("pack.info is invalid.")); return false; } - if (!utility.getEncryptPath().isEmpty() - && !isFileValid(utility.getEncryptPath(), Constants.FILE_ENCRYPT_JSON)) { - LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--encrypt-path is invalid.")); - return false; - } - if (!utility.getPacJsonPath().isEmpty() - && !isFileValid(utility.getPacJsonPath(), Constants.FILE_PAC_JSON)) { - LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pac-json-path is invalid.")); - return false; - } Path outPath = Paths.get(utility.getOutPath()); if (utility.getForceRewrite().equals(Constants.FALSE) && Files.exists(outPath)) { LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path file already existed, but " + @@ -858,6 +853,16 @@ public class PackageUtil { LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--entrycard-path is invalid.")); return false; } + if (!utility.getEncryptPath().isEmpty() + && !isFileMatch(utility.getEncryptPath(), Constants.FILE_ENCRYPT_JSON)) { + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--encrypt-path is invalid.")); + return false; + } + if (!utility.getPacJsonPath().isEmpty() + && !isFileMatch(utility.getPacJsonPath(), Constants.FILE_PAC_JSON)) { + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pac-json-path is invalid.")); + return false; + } if (utility.getOutPath().isEmpty()) { LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path is empty.")); return false; diff --git a/packing_tool/frameworks/include/packager.h b/packing_tool/frameworks/include/packager.h index 29ce735f21a6ede92da2e9b15eb84227c76c35dd..f98e646b790f2855fb8ce756f4b6132a8c27cba4 100644 --- a/packing_tool/frameworks/include/packager.h +++ b/packing_tool/frameworks/include/packager.h @@ -67,6 +67,7 @@ protected: bool CheckForceFlag(); bool IsPathValid(const std::string &path, const bool &isFile, const std::string suffix = ""); + bool IsFileMatch(const std::string &path, const std::string &matchFileName); bool SplitDirList(const std::string &dirList, std::list &fileList); void RemoveDuplicatePath(const std::string &path, std::list &pathList); bool CompatibleProcess(const std::string &inputPath, std::list &fileList, const std::string &suffix); diff --git a/packing_tool/frameworks/src/app_packager.cpp b/packing_tool/frameworks/src/app_packager.cpp index 8eca383601b603d07513b49b744a41b81471f38f..df0c2f8d21b806b8a73558f58e2ff4e0fb55bd28 100644 --- a/packing_tool/frameworks/src/app_packager.cpp +++ b/packing_tool/frameworks/src/app_packager.cpp @@ -326,7 +326,7 @@ bool AppPackager::CheckPacJsonPath() { auto it = parameterMap_.find(Constants::PARAM_PAC_JSON_PATH); if (it != parameterMap_.end() && !it->second.empty()) { - if (!IsPathValid(it->second, true, Constants::PAC_JSON)) { + if (!IsFileMatch(it->second, Constants::PAC_JSON)) { LOGE("pac-json-path is invalid."); return false; } diff --git a/packing_tool/frameworks/src/fast_app_packager.cpp b/packing_tool/frameworks/src/fast_app_packager.cpp index 7301761808aab2694c9d6cf359b824aafbe30b31..716a07d83620518f16c776c14903061122d67cc3 100644 --- a/packing_tool/frameworks/src/fast_app_packager.cpp +++ b/packing_tool/frameworks/src/fast_app_packager.cpp @@ -187,7 +187,7 @@ bool FastAppPackager::IsVerifyValid() it = parameterMap_.find(Constants::PARAM_PAC_JSON_PATH); if (it != parameterMap_.end() && !it->second.empty() && - !IsPathValid(it->second, true, Constants::PAC_JSON)) { + !IsFileMatch(it->second, Constants::PAC_JSON)) { LOGE("FastAppPackager::isVerifyValidInFastAppMode pac-json-path is invalid."); return false; } diff --git a/packing_tool/frameworks/src/multiapp_packager.cpp b/packing_tool/frameworks/src/multiapp_packager.cpp index c4a6c7692b57654790a6d0694766277a5a7eb6ce..ac9529800416d5e36a1a271e411ebb8e9df79ffa 100644 --- a/packing_tool/frameworks/src/multiapp_packager.cpp +++ b/packing_tool/frameworks/src/multiapp_packager.cpp @@ -145,6 +145,13 @@ bool MultiAppPackager::IsVerifyValidInMultiAppMode() return false; } + auto it = parameterMap_.find(Constants::PARAM_PAC_JSON_PATH); + if (it != parameterMap_.end() && !it->second.empty() && + !IsFileMatch(it->second, Constants::PAC_JSON)) { + LOGE("MultiAppPackager::IsVerifyValidInMultiAppMode pac-json-path is invalid."); + return false; + } + std::string outPath; if (!GetAndCheckOutPath(outPath)) { LOGE("GetAndCheckOutPath failed!"); @@ -152,7 +159,7 @@ bool MultiAppPackager::IsVerifyValidInMultiAppMode() } std::string force; - auto it = parameterMap_.find(Constants::PARAM_FORCE); + it = parameterMap_.find(Constants::PARAM_FORCE); if (it != parameterMap_.end() && !it->second.empty()) { force = it->second; if (Utils::IsFileExists(outPath) && force == "false") { @@ -161,13 +168,6 @@ bool MultiAppPackager::IsVerifyValidInMultiAppMode() } } - it = parameterMap_.find(Constants::PARAM_PAC_JSON_PATH); - if (it != parameterMap_.end() && !it->second.empty() && - !IsPathValid(it->second, true, Constants::PAC_JSON)) { - LOGE("MultiAppPackager::IsVerifyValidInMultiAppMode pac-json-path is invalid."); - return false; - } - return IsOutPathValid(outPath, force, Constants::MODE_MULTIAPP); } diff --git a/packing_tool/frameworks/src/packager.cpp b/packing_tool/frameworks/src/packager.cpp index 798abb55fff26ade5c79fafaefbf889f32f1625c..44da1a2b182b5f10f331cab246296f1b3ca9efd8 100644 --- a/packing_tool/frameworks/src/packager.cpp +++ b/packing_tool/frameworks/src/packager.cpp @@ -110,6 +110,19 @@ bool Packager::IsPathValid(const std::string &path, const bool &isFile, const st return (!isFile) && fs::is_directory(path); } +bool Packager::IsFileMatch(const std::string &path, const std::string &matchFileName) +{ + try { + if (fs::is_regular_file(path)) { + std::string name = fs::path(path).filename().string(); + return name == matchFileName; + } + } catch (const fs::filesystem_error& e) { + LOGE("Packager::commandVerify fileMatch has error : %s", e.code().message().c_str()); + } + return false; +} + bool Packager::SplitDirList(const std::string &dirList, std::list &fileList) { std::list pathList;