mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
Fix review comments.
Signed-off-by: dy_study <dingyao5@huawei.com> Change-Id: I8852176d392e54993817aab446bc8c648f9df16f
This commit is contained in:
@@ -25,7 +25,6 @@ ace_engine_path = "//foundation/arkui/ace_engine"
|
||||
|
||||
bundlefwk_path = "//foundation/bundlemanager/bundle_framework"
|
||||
bundlefwk_inner_api_path = "${bundlefwk_path}/interfaces/inner_api"
|
||||
bundlefwk_services_path = "${bundlefwk_path}/services"
|
||||
|
||||
multimedia_path = "//foundation/multimedia/image_standard"
|
||||
multimodalinput_path = "//foundation/multimodalinput/input"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -22,19 +22,11 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr const char* MODULE_PROFILE_NAME = "module.json";
|
||||
}
|
||||
|
||||
BaseExtractor::BaseExtractor(const std::string &source) : sourceFile_(source), zipFile_(source)
|
||||
{
|
||||
HILOG_DEBUG("BaseExtractor instance is created");
|
||||
}
|
||||
{}
|
||||
|
||||
BaseExtractor::~BaseExtractor()
|
||||
{
|
||||
HILOG_DEBUG("BaseExtractor instance is destroyed");
|
||||
}
|
||||
{}
|
||||
|
||||
bool BaseExtractor::Init()
|
||||
{
|
||||
@@ -43,9 +35,7 @@ bool BaseExtractor::Init()
|
||||
return false;
|
||||
}
|
||||
ZipEntry zipEntry;
|
||||
isNewVersion_ = zipFile_.GetEntry(MODULE_PROFILE_NAME, zipEntry);
|
||||
initial_ = true;
|
||||
HILOG_DEBUG("success");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -87,7 +77,6 @@ bool BaseExtractor::ExtractByName(const std::string &fileName, std::ostream &des
|
||||
|
||||
bool BaseExtractor::ExtractFile(const std::string &fileName, const std::string &targetPath) const
|
||||
{
|
||||
HILOG_DEBUG("begin to extract %{public}s file into %{private}s targetPath", fileName.c_str(), targetPath.c_str());
|
||||
std::ofstream fileStream;
|
||||
fileStream.open(targetPath, std::ios_base::out | std::ios_base::binary);
|
||||
if (!fileStream.is_open()) {
|
||||
@@ -125,13 +114,7 @@ bool BaseExtractor::IsStageBasedModel(std::string abilityName)
|
||||
std::string name = splitStrs.empty() ? abilityName : splitStrs.back();
|
||||
std::string entry = "assets/js/" + name + "/" + name + ".js";
|
||||
bool isStageBasedModel = entryMap.find(entry) != entryMap.end();
|
||||
HILOG_DEBUG("name:%{public}s isStageBasedModel:%{public}d", abilityName.c_str(), isStageBasedModel);
|
||||
return isStageBasedModel;
|
||||
}
|
||||
|
||||
bool BaseExtractor::IsNewVersion() const
|
||||
{
|
||||
return isNewVersion_;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -30,6 +30,23 @@ inline bool StringStartWith(const std::string& str, const char* startStr, size_t
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string GetLoadPath(const std::string& hapPath)
|
||||
{
|
||||
std::regex hapPattern(std::string(Constants::ABS_CODE_PATH) + std::string(Constants::FILE_SEPARATOR));
|
||||
std::string loadPath = std::regex_replace(hapPath, hapPattern, "");
|
||||
loadPath = std::string(Constants::LOCAL_CODE_PATH) + std::string(Constants::FILE_SEPARATOR) +
|
||||
loadPath.substr(loadPath.find(std::string(Constants::FILE_SEPARATOR)) + 1);
|
||||
return loadPath;
|
||||
}
|
||||
|
||||
std::string GetRelativePath(const std::string& srcPath)
|
||||
{
|
||||
std::regex srcPattern(std::string(Constants::LOCAL_CODE_PATH) + std::string(Constants::FILE_SEPARATOR));
|
||||
std::string relativePath = std::regex_replace(srcPath, srcPattern, "");
|
||||
relativePath = relativePath.substr(relativePath.find(std::string(Constants::FILE_SEPARATOR)) + 1);
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
std::shared_ptr<RuntimeExtractor> InitRuntimeExtractor(const std::string& hapPath)
|
||||
{
|
||||
if (hapPath.empty()) {
|
||||
@@ -39,10 +56,7 @@ std::shared_ptr<RuntimeExtractor> InitRuntimeExtractor(const std::string& hapPat
|
||||
|
||||
std::string loadPath;
|
||||
if (!StringStartWith(hapPath, Constants::SYSTEM_APP_PATH, sizeof(Constants::SYSTEM_APP_PATH) - 1)) {
|
||||
std::regex hapPattern(std::string(Constants::ABS_CODE_PATH) + std::string(Constants::FILE_SEPARATOR));
|
||||
loadPath = std::regex_replace(hapPath, hapPattern, "");
|
||||
loadPath = std::string(Constants::LOCAL_CODE_PATH) + std::string(Constants::FILE_SEPARATOR) +
|
||||
loadPath.substr(loadPath.find(std::string(Constants::FILE_SEPARATOR)) + 1);
|
||||
loadPath = GetLoadPath(hapPath);
|
||||
} else {
|
||||
loadPath = hapPath;
|
||||
}
|
||||
@@ -56,16 +70,14 @@ std::shared_ptr<RuntimeExtractor> InitRuntimeExtractor(const std::string& hapPat
|
||||
}
|
||||
|
||||
bool GetFileBuffer(
|
||||
const std::shared_ptr<RuntimeExtractor>& runtimeExtractor, const std::string& srcPath, std::ostringstream &dest)
|
||||
const std::shared_ptr<RuntimeExtractor>& runtimeExtractor, const std::string& srcPath, std::ostringstream& dest)
|
||||
{
|
||||
if (runtimeExtractor == nullptr || srcPath.empty()) {
|
||||
HILOG_ERROR("GetFileBuffer::runtimeExtractor or srcPath is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::regex srcPattern(std::string(Constants::LOCAL_CODE_PATH) + std::string(Constants::FILE_SEPARATOR));
|
||||
std::string relativePath = std::regex_replace(srcPath, srcPattern, "");
|
||||
relativePath = relativePath.substr(relativePath.find(std::string(Constants::FILE_SEPARATOR)) + 1);
|
||||
std::string relativePath = GetRelativePath(srcPath);
|
||||
if (!runtimeExtractor->ExtractByName(relativePath, dest)) {
|
||||
HILOG_ERROR("GetFileBuffer::Extract file failed");
|
||||
return false;
|
||||
@@ -73,61 +85,5 @@ bool GetFileBuffer(
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetFileBufferFromHap(const std::string& hapPath, const std::string& srcPath, std::ostringstream &dest)
|
||||
{
|
||||
if (hapPath.empty() || srcPath.empty()) {
|
||||
HILOG_ERROR("GetFileBufferFromHap::hapPath or srcPath is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
return GetFileBuffer(InitRuntimeExtractor(hapPath), srcPath, dest);
|
||||
}
|
||||
|
||||
bool GetFileListFromHap(const std::string& hapPath, const std::string& srcPath, std::vector<std::string>& assetList)
|
||||
{
|
||||
if (hapPath.empty() || srcPath.empty()) {
|
||||
HILOG_ERROR("GetFileListFromHap::hapPath or srcPath is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string loadPath;
|
||||
if (!StringStartWith(hapPath, Constants::SYSTEM_APP_PATH, sizeof(Constants::SYSTEM_APP_PATH) - 1)) {
|
||||
std::regex hapPattern(std::string(Constants::ABS_CODE_PATH) + std::string(Constants::FILE_SEPARATOR));
|
||||
loadPath = std::regex_replace(hapPath, hapPattern, "");
|
||||
loadPath = std::string(Constants::LOCAL_CODE_PATH) + std::string(Constants::FILE_SEPARATOR) +
|
||||
loadPath.substr(loadPath.find(std::string(Constants::FILE_SEPARATOR)) + 1);
|
||||
} else {
|
||||
loadPath = hapPath;
|
||||
}
|
||||
RuntimeExtractor runtimeExtractor(loadPath);
|
||||
if (!runtimeExtractor.Init()) {
|
||||
HILOG_ERROR("GetFileListFromHap::Runtime extractor init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::regex srcPattern(std::string(Constants::LOCAL_CODE_PATH) + std::string(Constants::FILE_SEPARATOR));
|
||||
std::string relativePath = std::regex_replace(srcPath, srcPattern, "");
|
||||
relativePath = relativePath.substr(relativePath.find(std::string(Constants::FILE_SEPARATOR)) + 1);
|
||||
|
||||
std::vector<std::string> fileList;
|
||||
if (!runtimeExtractor.GetZipFileNames(fileList)) {
|
||||
HILOG_ERROR("GetFileListFromHap::Get file list failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::regex replacePattern(relativePath);
|
||||
for (auto value : fileList) {
|
||||
if (StringStartWith(value, relativePath.c_str(), sizeof(relativePath.c_str()) - 1)) {
|
||||
std::string realpath = std::regex_replace(value, replacePattern, "");
|
||||
if (realpath.find(Constants::FILE_SEPARATOR) != std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
assetList.emplace_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -25,7 +25,7 @@ class RuntimeExtractor;
|
||||
|
||||
class JsModuleReader final {
|
||||
public:
|
||||
explicit JsModuleReader(const std::string& bundleName, const std::string& hapPath,
|
||||
JsModuleReader(const std::string& bundleName, const std::string& hapPath,
|
||||
const std::shared_ptr<RuntimeExtractor>& runtimeExtractor)
|
||||
: bundleName_(bundleName), hapPath_(hapPath), runtimeExtractor_(runtimeExtractor)
|
||||
{}
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#include "hdc_register.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_console_log.h"
|
||||
#include "js_module_searcher.h"
|
||||
#include "js_module_reader.h"
|
||||
#include "js_module_searcher.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_timer.h"
|
||||
#include "js_worker.h"
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
debugMode_ = true;
|
||||
}
|
||||
|
||||
bool RunScript(const std::string& path, const std::string& hapPath) override
|
||||
bool RunScript(const std::string& srcPath, const std::string& hapPath) override
|
||||
{
|
||||
bool result = false;
|
||||
if (!hapPath.empty()) {
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
if (runtimeExtractor_ == nullptr) {
|
||||
runtimeExtractor_ = InitRuntimeExtractor(hapPath);
|
||||
}
|
||||
if (!GetFileBuffer(runtimeExtractor_, path, outStream)) {
|
||||
if (!GetFileBuffer(runtimeExtractor_, srcPath, outStream)) {
|
||||
HILOG_ERROR("Get abc file failed");
|
||||
return result;
|
||||
}
|
||||
@@ -126,9 +126,9 @@ public:
|
||||
std::vector<uint8_t> buffer;
|
||||
buffer.assign(outStr.begin(), outStr.end());
|
||||
|
||||
result = nativeEngine_->RunScriptBuffer(path.c_str(), buffer) != nullptr;
|
||||
result = nativeEngine_->RunScriptBuffer(srcPath.c_str(), buffer) != nullptr;
|
||||
} else {
|
||||
result = nativeEngine_->RunScriptPath(path.c_str()) != nullptr;
|
||||
result = nativeEngine_->RunScriptPath(srcPath.c_str()) != nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
NativeValue* LoadJsModule(const std::string& path, const std::string& hapPath) override
|
||||
{
|
||||
if (!RunScript(path, hapPath)) {
|
||||
HILOG_ERROR("Failed to run script: %{public}s", path.c_str());
|
||||
HILOG_ERROR("Failed to run script: %{private}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -200,9 +200,12 @@ private:
|
||||
if (!options.preload) {
|
||||
bundleName_ = options.bundleName;
|
||||
runtimeExtractor_ = InitRuntimeExtractor(options.hapPath);
|
||||
panda::JSNApi::SetHostResolvePathTracker(vm_, JsModuleSearcher(options.bundleName));
|
||||
panda::JSNApi::SetHostResolveBufferTracker(
|
||||
vm_, JsModuleReader(options.bundleName, options.hapPath, runtimeExtractor_));
|
||||
if (!options.hapPath.empty()) {
|
||||
panda::JSNApi::SetHostResolveBufferTracker(
|
||||
vm_, JsModuleReader(options.bundleName, options.hapPath, runtimeExtractor_));
|
||||
} else {
|
||||
panda::JSNApi::SetHostResolvePathTracker(vm_, JsModuleSearcher(options.bundleName));
|
||||
}
|
||||
}
|
||||
return JsRuntime::Initialize(options);
|
||||
}
|
||||
@@ -462,19 +465,19 @@ NativeValue* JsRuntime::LoadJsBundle(const std::string& path, const std::string&
|
||||
globalObj->SetProperty("exports", exports);
|
||||
|
||||
if (!RunScript(path, hapPath)) {
|
||||
HILOG_ERROR("Failed to run script: %{public}s", path.c_str());
|
||||
HILOG_ERROR("Failed to run script: %{private}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeObject* exportsObj = ConvertNativeValueTo<NativeObject>(globalObj->GetProperty("exports"));
|
||||
if (exportsObj == nullptr) {
|
||||
HILOG_ERROR("Failed to get exports objcect: %{public}s", path.c_str());
|
||||
HILOG_ERROR("Failed to get exports objcect: %{private}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue* exportObj = exportsObj->GetProperty("default");
|
||||
if (exportObj == nullptr) {
|
||||
HILOG_ERROR("Failed to get default objcect: %{public}s", path.c_str());
|
||||
HILOG_ERROR("Failed to get default objcect: %{private}s", path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -484,7 +487,7 @@ NativeValue* JsRuntime::LoadJsBundle(const std::string& path, const std::string&
|
||||
std::unique_ptr<NativeReference> JsRuntime::LoadModule(
|
||||
const std::string& moduleName, const std::string& modulePath, const std::string& hapPath, bool esmodule)
|
||||
{
|
||||
HILOG_DEBUG("JsRuntime::LoadModule(%{public}s, %{public}s, %{public}s, %{public}s)",
|
||||
HILOG_DEBUG("JsRuntime::LoadModule(%{public}s, %{private}s, %{private}s, %{public}s)",
|
||||
moduleName.c_str(), modulePath.c_str(), hapPath.c_str(), esmodule ? "true" : "false");
|
||||
|
||||
HandleScope handleScope(*this);
|
||||
@@ -537,7 +540,7 @@ std::unique_ptr<NativeReference> JsRuntime::LoadSystemModule(
|
||||
return std::unique_ptr<NativeReference>(nativeEngine_->CreateReference(instanceValue, 1));
|
||||
}
|
||||
|
||||
bool JsRuntime::RunScript(const std::string& path, const std::string& hapPath)
|
||||
bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath)
|
||||
{
|
||||
bool result = false;
|
||||
if (!hapPath.empty()) {
|
||||
@@ -545,7 +548,7 @@ bool JsRuntime::RunScript(const std::string& path, const std::string& hapPath)
|
||||
if (runtimeExtractor_ == nullptr) {
|
||||
runtimeExtractor_ = InitRuntimeExtractor(hapPath);
|
||||
}
|
||||
if (!GetFileBuffer(runtimeExtractor_, path, outStream)) {
|
||||
if (!GetFileBuffer(runtimeExtractor_, srcPath, outStream)) {
|
||||
HILOG_ERROR("Get abc file failed");
|
||||
return result;
|
||||
}
|
||||
@@ -554,9 +557,9 @@ bool JsRuntime::RunScript(const std::string& path, const std::string& hapPath)
|
||||
std::vector<uint8_t> buffer;
|
||||
buffer.assign(outStr.begin(), outStr.end());
|
||||
|
||||
result = nativeEngine_->RunScriptBuffer(path.c_str(), buffer) != nullptr;
|
||||
result = nativeEngine_->RunScriptBuffer(srcPath.c_str(), buffer) != nullptr;
|
||||
} else {
|
||||
result = nativeEngine_->RunScript(path.c_str()) != nullptr;
|
||||
result = nativeEngine_->RunScript(srcPath.c_str()) != nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -53,6 +53,8 @@ constexpr char BUNDLE_INSTALL_PATH[] = "/data/storage/el1/bundle/";
|
||||
constexpr char OTHER_BUNDLE_INSTALL_PATH[] = "/data/bundles/";
|
||||
|
||||
constexpr size_t MAX_NPM_LEVEL = 1;
|
||||
constexpr size_t SEGMENTS_LIMIT_TWO = 2;
|
||||
constexpr size_t SEGMENTS_LIMIT_THREE = 3;
|
||||
|
||||
std::unique_ptr<AsyncTask> CreateAsyncTaskWithLastParam(NativeEngine& engine, NativeValue* lastParam,
|
||||
std::unique_ptr<AsyncTask::ExecuteCallback>&& execute, std::unique_ptr<AsyncTask::CompleteCallback>&& complete,
|
||||
@@ -458,7 +460,16 @@ std::string FindNpmPackageInPath(const std::string& npmPath)
|
||||
stream.seekg(0);
|
||||
stream.read(path, fileLen);
|
||||
path[fileLen] = '\0';
|
||||
return npmPath + '/' + StripString(path);
|
||||
stream.close();
|
||||
|
||||
std::string npmPackagePath = npmPath + '/' + StripString(path);
|
||||
if (npmPackagePath.size() >= PATH_MAX) {
|
||||
return std::string();
|
||||
}
|
||||
if (realpath(npmPackagePath.c_str(), path) == nullptr) {
|
||||
return std::string();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string FindNpmPackageInTopLevel(
|
||||
@@ -521,7 +532,7 @@ std::string FindNpmPackage(const std::string& curJsModulePath, const std::string
|
||||
}
|
||||
|
||||
std::string ParseOhmUri(
|
||||
const std::string originBundleName, const std::string& curJsModulePath, const std::string& newJsModuleUri)
|
||||
const std::string& originBundleName, const std::string& curJsModulePath, const std::string& newJsModuleUri)
|
||||
{
|
||||
std::string moduleInstallPath;
|
||||
std::vector<std::string> pathVector;
|
||||
@@ -531,7 +542,7 @@ std::string ParseOhmUri(
|
||||
SplitString(newJsModuleUri, pathVector, sizeof(PREFIX_BUNDLE) - 1);
|
||||
|
||||
// Uri should have atleast 3 segments
|
||||
if (pathVector.size() < 3) {
|
||||
if (pathVector.size() < SEGMENTS_LIMIT_THREE) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
@@ -547,7 +558,7 @@ std::string ParseOhmUri(
|
||||
SplitString(newJsModuleUri, pathVector, sizeof(PREFIX_MODULE) - 1);
|
||||
|
||||
// Uri should have atleast 2 segments
|
||||
if (pathVector.size() < 2) {
|
||||
if (pathVector.size() < SEGMENTS_LIMIT_TWO) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
@@ -583,7 +594,7 @@ bool MakeFilePath(const std::string& codePath, const std::string& modulePath, st
|
||||
std::string path(codePath);
|
||||
path.append("/").append(modulePath);
|
||||
if (path.length() > PATH_MAX) {
|
||||
HILOG_ERROR("Path length(%{public}d) longer than MAX(%{public}d)", (int32_t)path.length(), PATH_MAX);
|
||||
HILOG_ERROR("Path length(%{public}zu) longer than MAX(%{public}d)", path.length(), PATH_MAX);
|
||||
return false;
|
||||
}
|
||||
char resolvedPath[PATH_MAX + 1] = { 0 };
|
||||
@@ -606,7 +617,7 @@ bool MakeFilePath(const std::string& codePath, const std::string& modulePath, st
|
||||
}
|
||||
|
||||
path.erase(start + 1, pos - start);
|
||||
HILOG_INFO("Try using secondary file path: %{public}s", path.c_str());
|
||||
HILOG_DEBUG("Try using secondary file path: %{private}s", path.c_str());
|
||||
|
||||
if (realpath(path.c_str(), resolvedPath) == nullptr) {
|
||||
HILOG_ERROR("Failed to call realpath, errno = %{public}d", errno);
|
||||
|
||||
@@ -19,23 +19,19 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
RuntimeExtractor::RuntimeExtractor(const std::string &source) : BaseExtractor(source)
|
||||
{
|
||||
HILOG_DEBUG("RuntimeExtractor is created");
|
||||
}
|
||||
RuntimeExtractor::RuntimeExtractor(const std::string& source) : BaseExtractor(source)
|
||||
{}
|
||||
|
||||
RuntimeExtractor::RuntimeExtractor(
|
||||
const std::string &source, const std::string &hapPath) : BaseExtractor(source)
|
||||
const std::string& source, const std::string& hapPath) : BaseExtractor(source)
|
||||
{
|
||||
hapPath_ = hapPath;
|
||||
}
|
||||
|
||||
RuntimeExtractor::~RuntimeExtractor()
|
||||
{
|
||||
HILOG_DEBUG("RuntimeExtractor destroyed");
|
||||
}
|
||||
{}
|
||||
|
||||
bool RuntimeExtractor::isSameHap(const std::string &hapPath) const
|
||||
bool RuntimeExtractor::isSameHap(const std::string& hapPath) const
|
||||
{
|
||||
return !hapPath_.empty() && !hapPath.empty() && hapPath_ == hapPath;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -51,9 +51,7 @@ ZipEntry::ZipEntry(const CentralDirEntry ¢ralEntry)
|
||||
}
|
||||
|
||||
ZipFile::ZipFile(const std::string &pathName) : pathName_(pathName)
|
||||
{
|
||||
HILOG_DEBUG("create instance from %{private}s", pathName_.c_str());
|
||||
}
|
||||
{}
|
||||
|
||||
ZipFile::~ZipFile()
|
||||
{
|
||||
@@ -62,7 +60,6 @@ ZipFile::~ZipFile()
|
||||
|
||||
void ZipFile::SetContentLocation(const ZipPos start, const size_t length)
|
||||
{
|
||||
HILOG_DEBUG("set content location start position(%{public}llu), length(%{public}zu)", start, length);
|
||||
fileStartPos_ = start;
|
||||
fileLength_ = length;
|
||||
}
|
||||
@@ -103,8 +100,6 @@ bool ZipFile::ParseEndDirectory()
|
||||
}
|
||||
|
||||
centralDirPos_ = endDir_.offset + fileStartPos_;
|
||||
HILOG_DEBUG("parse EOCD offset(0x%{public}08x) file start position(0x%{public}08llx)",
|
||||
endDir_.offset, fileStartPos_);
|
||||
|
||||
return CheckEndDir(endDir_);
|
||||
}
|
||||
@@ -157,15 +152,11 @@ bool ZipFile::ParseAllEntries()
|
||||
currentPos += sizeof(directoryEntry);
|
||||
currentPos += directoryEntry.nameSize + directoryEntry.extraSize + directoryEntry.commentSize;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("parse %{public}d central entries from %{private}s", endDir_.totalEntries, pathName_.c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ZipFile::Open()
|
||||
{
|
||||
HILOG_DEBUG("open: %{private}s", pathName_.c_str());
|
||||
|
||||
if (isOpen_) {
|
||||
HILOG_ERROR("has already opened");
|
||||
return true;
|
||||
@@ -225,8 +216,6 @@ bool ZipFile::Open()
|
||||
|
||||
void ZipFile::Close()
|
||||
{
|
||||
HILOG_DEBUG("close: %{private}s", pathName_.c_str());
|
||||
|
||||
if (!isOpen_ || file_ == nullptr) {
|
||||
HILOG_WARN("file is not opened");
|
||||
return;
|
||||
@@ -255,7 +244,6 @@ bool ZipFile::HasEntry(const std::string &entryName) const
|
||||
|
||||
bool ZipFile::IsDirExist(const std::string &dir) const
|
||||
{
|
||||
HILOG_DEBUG("target dir: %{public}s", dir.c_str());
|
||||
if (dir.empty()) {
|
||||
HILOG_ERROR("target dir is empty");
|
||||
return false;
|
||||
@@ -268,24 +256,21 @@ bool ZipFile::IsDirExist(const std::string &dir) const
|
||||
|
||||
for (const auto &item : entriesMap_) {
|
||||
if (item.first.find(tempDir) == 0) {
|
||||
HILOG_DEBUG("find target dir, fileName : %{public}s", item.first.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
HILOG_DEBUG("target dir not found, dir : %{public}s", dir.c_str());
|
||||
HILOG_ERROR("target dir not found, dir : %{private}s", dir.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZipFile::GetEntry(const std::string &entryName, ZipEntry &resultEntry) const
|
||||
{
|
||||
HILOG_DEBUG("get entry by name: %{public}s", entryName.c_str());
|
||||
auto iter = entriesMap_.find(entryName);
|
||||
if (iter != entriesMap_.end()) {
|
||||
resultEntry = iter->second;
|
||||
HILOG_DEBUG("get entry succeed");
|
||||
return true;
|
||||
}
|
||||
HILOG_ERROR("get entry failed");
|
||||
HILOG_ERROR("get entry %{public}s failed", entryName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -410,7 +395,6 @@ bool ZipFile::SeekToEntryStart(const ZipEntry &zipEntry, const uint16_t extraSiz
|
||||
}
|
||||
startOffset += fileStartPos_; // add file start relative to file stream
|
||||
|
||||
HILOG_DEBUG("seek to entry start 0x%{public}08llx", startOffset);
|
||||
if (fseek(file_, startOffset, SEEK_SET) != 0) {
|
||||
HILOG_ERROR("seek failed, error: %{public}d", errno);
|
||||
return false;
|
||||
@@ -420,8 +404,6 @@ bool ZipFile::SeekToEntryStart(const ZipEntry &zipEntry, const uint16_t extraSiz
|
||||
|
||||
bool ZipFile::UnzipWithStore(const ZipEntry &zipEntry, const uint16_t extraSize, std::ostream &dest) const
|
||||
{
|
||||
HILOG_DEBUG("unzip with store");
|
||||
|
||||
if (!SeekToEntryStart(zipEntry, extraSize)) {
|
||||
HILOG_ERROR("seek to entry start failed");
|
||||
return false;
|
||||
@@ -497,8 +479,6 @@ bool ZipFile::ReadZStream(const BytePtr &buffer, z_stream &zstream, uint32_t &re
|
||||
|
||||
bool ZipFile::UnzipWithInflated(const ZipEntry &zipEntry, const uint16_t extraSize, std::ostream &dest) const
|
||||
{
|
||||
HILOG_DEBUG("unzip with inflated");
|
||||
|
||||
z_stream zstream;
|
||||
if (!SeekToEntryStart(zipEntry, extraSize) || !InitZStream(zstream)) {
|
||||
return false;
|
||||
@@ -566,8 +546,6 @@ ZipPos ZipFile::GetEntryDataOffset(const ZipEntry &zipEntry, const uint16_t extr
|
||||
|
||||
bool ZipFile::GetDataOffsetRelative(const std::string &file, ZipPos &offset, uint32_t &length) const
|
||||
{
|
||||
HILOG_DEBUG("get data relative offset for file %{private}s", file.c_str());
|
||||
|
||||
ZipEntry zipEntry;
|
||||
if (!GetEntry(file, zipEntry)) {
|
||||
HILOG_ERROR("extract file: not find file");
|
||||
@@ -587,8 +565,6 @@ bool ZipFile::GetDataOffsetRelative(const std::string &file, ZipPos &offset, uin
|
||||
|
||||
bool ZipFile::ExtractFile(const std::string &file, std::ostream &dest) const
|
||||
{
|
||||
HILOG_DEBUG("extract file %{private}s", file.c_str());
|
||||
|
||||
ZipEntry zipEntry;
|
||||
if (!GetEntry(file, zipEntry)) {
|
||||
HILOG_ERROR("extract file: not find file");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -59,14 +59,11 @@ public:
|
||||
bool HasEntry(const std::string &fileName) const;
|
||||
bool IsDirExist(const std::string &dir) const;
|
||||
bool IsStageBasedModel(std::string abilityName);
|
||||
bool IsNewVersion() const;
|
||||
|
||||
protected:
|
||||
const std::string sourceFile_;
|
||||
ZipFile zipFile_;
|
||||
bool initial_ = false;
|
||||
private:
|
||||
bool isNewVersion_ = true;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -22,9 +22,7 @@ namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
std::shared_ptr<RuntimeExtractor> InitRuntimeExtractor(const std::string& hapPath);
|
||||
bool GetFileBuffer(
|
||||
const std::shared_ptr<RuntimeExtractor>& runtimeExtractor, const std::string& srcPath, std::ostringstream &dest);
|
||||
bool GetFileBufferFromHap(const std::string& hapPath, const std::string& srcPath, std::ostringstream &dest);
|
||||
bool GetFileListFromHap(const std::string& hapPath, const std::string& srcPath, std::vector<std::string>& assetList);
|
||||
const std::shared_ptr<RuntimeExtractor>& runtimeExtractor, const std::string& srcPath, std::ostringstream& dest);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -195,7 +195,7 @@ std::string FindNpmPackageInTopLevel(
|
||||
const std::string& moduleInstallPath, const std::string& npmPackage, size_t start = 0);
|
||||
std::string FindNpmPackage(const std::string& curJsModulePath, const std::string& npmPackage);
|
||||
std::string ParseOhmUri(
|
||||
const std::string bundleName, const std::string& curJsModulePath, const std::string& newJsModuleUri);
|
||||
const std::string& originBundleName, const std::string& curJsModulePath, const std::string& newJsModuleUri);
|
||||
std::string ParseJsModuleUri(const std::string& curJsModulePath, const std::string& newJsModuleUri);
|
||||
bool MakeFilePath(const std::string& codePath, const std::string& modulePath, std::string& fileName);
|
||||
std::string NormalizeUri(
|
||||
|
||||
@@ -22,11 +22,11 @@ namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class RuntimeExtractor : public BaseExtractor {
|
||||
public:
|
||||
explicit RuntimeExtractor(const std::string &source);
|
||||
explicit RuntimeExtractor(const std::string &source, const std::string &hapPath);
|
||||
explicit RuntimeExtractor(const std::string& source);
|
||||
RuntimeExtractor(const std::string& source, const std::string& hapPath);
|
||||
virtual ~RuntimeExtractor() override;
|
||||
|
||||
bool isSameHap(const std::string &hapPath) const;
|
||||
bool isSameHap(const std::string& hapPath) const;
|
||||
|
||||
private:
|
||||
std::string hapPath_;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
Reference in New Issue
Block a user