1fb299fa2Sopenharmony_ci/* 2fb299fa2Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at 6fb299fa2Sopenharmony_ci * 7fb299fa2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb299fa2Sopenharmony_ci * 9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and 13fb299fa2Sopenharmony_ci * limitations under the License. 14fb299fa2Sopenharmony_ci */ 15fb299fa2Sopenharmony_ci 16fb299fa2Sopenharmony_ci#include "bin_process.h" 17fb299fa2Sopenharmony_ci#include <string> 18fb299fa2Sopenharmony_ci#include <thread> 19fb299fa2Sopenharmony_ci#include "applypatch/partition_record.h" 20fb299fa2Sopenharmony_ci#include "log.h" 21fb299fa2Sopenharmony_ci#include "pkg_manager_impl.h" 22fb299fa2Sopenharmony_ci#include "pkg_package/pkg_pkgfile.h" 23fb299fa2Sopenharmony_ci#include "pkg_utils.h" 24fb299fa2Sopenharmony_ci#include "ring_buffer/ring_buffer.h" 25fb299fa2Sopenharmony_ci#include "script_manager.h" 26fb299fa2Sopenharmony_ci#include "threadpool/thread_pool.h" 27fb299fa2Sopenharmony_ci#include "scope_guard.h" 28fb299fa2Sopenharmony_ci#include "securec.h" 29fb299fa2Sopenharmony_ci 30fb299fa2Sopenharmony_ciusing namespace std; 31fb299fa2Sopenharmony_ciusing namespace Hpackage; 32fb299fa2Sopenharmony_ciusing namespace Uscript; 33fb299fa2Sopenharmony_ci 34fb299fa2Sopenharmony_cinamespace Updater { 35fb299fa2Sopenharmony_ciconstexpr uint32_t STASH_BUFFER_SIZE = 4 * 1024 * 1024; 36fb299fa2Sopenharmony_ciconstexpr uint32_t MAX_BUFFER_NUM = 16; 37fb299fa2Sopenharmony_ciconstexpr uint8_t ES_IMAGE = 6; 38fb299fa2Sopenharmony_ciconstexpr uint8_t CS_IMAGE = 7; 39fb299fa2Sopenharmony_ciconstexpr uint8_t NEED_VERIFY_CS_IMAGE = 8; 40fb299fa2Sopenharmony_ci 41fb299fa2Sopenharmony_ciint32_t UScriptInstructionBinFlowWrite::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) 42fb299fa2Sopenharmony_ci{ 43fb299fa2Sopenharmony_ci std::string upgradeFileName; 44fb299fa2Sopenharmony_ci int32_t ret = context.GetParam(0, upgradeFileName); 45fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 46fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get bin file"; 47fb299fa2Sopenharmony_ci return ret; 48fb299fa2Sopenharmony_ci } 49fb299fa2Sopenharmony_ci 50fb299fa2Sopenharmony_ci LOG(INFO) << "UScriptInstructionUpdateFromZip::Execute " << upgradeFileName; 51fb299fa2Sopenharmony_ci PkgManager::PkgManagerPtr pkgManager = env.GetPkgManager(); 52fb299fa2Sopenharmony_ci if (pkgManager == nullptr) { 53fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get pkg manager"; 54fb299fa2Sopenharmony_ci return USCRIPT_INVALID_PARAM; 55fb299fa2Sopenharmony_ci } 56fb299fa2Sopenharmony_ci 57fb299fa2Sopenharmony_ci RingBuffer ringBuffer; 58fb299fa2Sopenharmony_ci if (!ringBuffer.Init(STASH_BUFFER_SIZE, MAX_BUFFER_NUM)) { 59fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get ringbuffer"; 60fb299fa2Sopenharmony_ci return USCRIPT_INVALID_PARAM; 61fb299fa2Sopenharmony_ci } 62fb299fa2Sopenharmony_ci 63fb299fa2Sopenharmony_ci fullUpdateProportion_ = GetScriptProportion(); 64fb299fa2Sopenharmony_ci stashBuffer_.data.resize(STASH_BUFFER_SIZE); 65fb299fa2Sopenharmony_ci stashBuffer_.buffer = stashBuffer_.data.data(); 66fb299fa2Sopenharmony_ci PkgManager::StreamPtr binFlowStream = nullptr; 67fb299fa2Sopenharmony_ci const FileInfo *info = pkgManager->GetFileInfo(upgradeFileName); 68fb299fa2Sopenharmony_ci if (info == nullptr) { 69fb299fa2Sopenharmony_ci LOG(ERROR) << "Get file info fail " << upgradeFileName; 70fb299fa2Sopenharmony_ci return PKG_INVALID_FILE; 71fb299fa2Sopenharmony_ci } 72fb299fa2Sopenharmony_ci ret = pkgManager->CreatePkgStream(binFlowStream, upgradeFileName, info->unpackedSize, &ringBuffer); 73fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS || binFlowStream == nullptr) { 74fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to create output stream"; 75fb299fa2Sopenharmony_ci return USCRIPT_INVALID_PARAM; 76fb299fa2Sopenharmony_ci } 77fb299fa2Sopenharmony_ci 78fb299fa2Sopenharmony_ci std::thread consumer([this, &env, &context, binFlowStream] { 79fb299fa2Sopenharmony_ci this->ProcessBinFile(env, context, binFlowStream); 80fb299fa2Sopenharmony_ci }); 81fb299fa2Sopenharmony_ci std::thread producer([this, &env, &context, binFlowStream] { 82fb299fa2Sopenharmony_ci this->ExtractBinFile(env, context, binFlowStream); 83fb299fa2Sopenharmony_ci }); 84fb299fa2Sopenharmony_ci consumer.join(); 85fb299fa2Sopenharmony_ci producer.join(); 86fb299fa2Sopenharmony_ci if (isStopRun_) { 87fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to Execute bin file update"; 88fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 89fb299fa2Sopenharmony_ci } 90fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 91fb299fa2Sopenharmony_ci} 92fb299fa2Sopenharmony_ci 93fb299fa2Sopenharmony_ciint32_t UScriptInstructionBinFlowWrite::ExtractBinFile(Uscript::UScriptEnv &env, Uscript::UScriptContext &context, 94fb299fa2Sopenharmony_ci PkgManager::StreamPtr stream) 95fb299fa2Sopenharmony_ci{ 96fb299fa2Sopenharmony_ci ON_SCOPE_EXIT(failExecute) { 97fb299fa2Sopenharmony_ci isStopRun_ = true; 98fb299fa2Sopenharmony_ci stream->Stop(); 99fb299fa2Sopenharmony_ci }; 100fb299fa2Sopenharmony_ci std::string upgradeFileName; 101fb299fa2Sopenharmony_ci int32_t ret = context.GetParam(0, upgradeFileName); 102fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 103fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get bin file"; 104fb299fa2Sopenharmony_ci return ret; 105fb299fa2Sopenharmony_ci } 106fb299fa2Sopenharmony_ci 107fb299fa2Sopenharmony_ci LOG(INFO) << "UScriptInstructionBinFlowWrite::ExtractBinFile " << upgradeFileName; 108fb299fa2Sopenharmony_ci PkgManager::PkgManagerPtr pkgManager = env.GetPkgManager(); 109fb299fa2Sopenharmony_ci if (pkgManager == nullptr) { 110fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get pkg manager"; 111fb299fa2Sopenharmony_ci return USCRIPT_INVALID_PARAM; 112fb299fa2Sopenharmony_ci } 113fb299fa2Sopenharmony_ci 114fb299fa2Sopenharmony_ci PkgManager::StreamPtr processStream = nullptr; 115fb299fa2Sopenharmony_ci PkgStream::ExtractFileProcessor processor = 116fb299fa2Sopenharmony_ci [this](const PkgBuffer &buffer, size_t size, size_t start, bool isFinish, const void *context) { 117fb299fa2Sopenharmony_ci return this->UnCompressDataProducer(buffer, size, start, isFinish, context); 118fb299fa2Sopenharmony_ci }; 119fb299fa2Sopenharmony_ci ret = pkgManager->CreatePkgStream(processStream, upgradeFileName, processor, stream); 120fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS || processStream == nullptr) { 121fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to create output stream"; 122fb299fa2Sopenharmony_ci return USCRIPT_INVALID_PARAM; 123fb299fa2Sopenharmony_ci } 124fb299fa2Sopenharmony_ci 125fb299fa2Sopenharmony_ci ret = pkgManager->ExtractFile(upgradeFileName, processStream); 126fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 127fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to extract" << upgradeFileName; 128fb299fa2Sopenharmony_ci pkgManager->ClosePkgStream(processStream); 129fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 130fb299fa2Sopenharmony_ci } 131fb299fa2Sopenharmony_ci pkgManager->ClosePkgStream(processStream); 132fb299fa2Sopenharmony_ci CANCEL_SCOPE_EXIT_GUARD(failExecute); 133fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 134fb299fa2Sopenharmony_ci} 135fb299fa2Sopenharmony_ci 136fb299fa2Sopenharmony_ciint32_t UScriptInstructionBinFlowWrite::UnCompressDataProducer(const PkgBuffer &buffer, size_t size, size_t start, 137fb299fa2Sopenharmony_ci bool isFinish, const void *context) 138fb299fa2Sopenharmony_ci{ 139fb299fa2Sopenharmony_ci if (isStopRun_) { 140fb299fa2Sopenharmony_ci LOG(ERROR) << "recive stop single, UnCompressDataProducer stop run"; 141fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 142fb299fa2Sopenharmony_ci } 143fb299fa2Sopenharmony_ci 144fb299fa2Sopenharmony_ci void *p = const_cast<void *>(context); 145fb299fa2Sopenharmony_ci PkgStream *flowStream = static_cast<PkgStream *>(p); 146fb299fa2Sopenharmony_ci if (flowStream == nullptr) { 147fb299fa2Sopenharmony_ci LOG(ERROR) << "ring buffer is nullptr"; 148fb299fa2Sopenharmony_ci return PKG_INVALID_STREAM; 149fb299fa2Sopenharmony_ci } 150fb299fa2Sopenharmony_ci 151fb299fa2Sopenharmony_ci if (buffer.buffer == nullptr && size == 0 && isFinish) { 152fb299fa2Sopenharmony_ci // 最后一块数据 153fb299fa2Sopenharmony_ci if (stashDataSize_ != 0) { 154fb299fa2Sopenharmony_ci size_t writeOffset = flowStream->GetFileLength() - stashDataSize_; 155fb299fa2Sopenharmony_ci if (flowStream->Write(stashBuffer_, stashDataSize_, writeOffset) != USCRIPT_SUCCESS) { 156fb299fa2Sopenharmony_ci LOG(ERROR) << "UnCompress flowStream write fail"; 157fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 158fb299fa2Sopenharmony_ci } 159fb299fa2Sopenharmony_ci stashDataSize_ = 0; 160fb299fa2Sopenharmony_ci } 161fb299fa2Sopenharmony_ci LOG(INFO) << "extract finished, start"; 162fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 163fb299fa2Sopenharmony_ci } 164fb299fa2Sopenharmony_ci 165fb299fa2Sopenharmony_ci if (buffer.buffer == nullptr || size == 0 || start < stashDataSize_) { 166fb299fa2Sopenharmony_ci LOG(ERROR) << "invalid para, size: " << size << "start: " << start; 167fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 168fb299fa2Sopenharmony_ci } 169fb299fa2Sopenharmony_ci 170fb299fa2Sopenharmony_ci size_t writeSize = 0; 171fb299fa2Sopenharmony_ci size_t copyLen = 0; 172fb299fa2Sopenharmony_ci // 缓存4M再写入数据流 173fb299fa2Sopenharmony_ci while (size - writeSize > STASH_BUFFER_SIZE - stashDataSize_) { 174fb299fa2Sopenharmony_ci copyLen = STASH_BUFFER_SIZE - stashDataSize_; 175fb299fa2Sopenharmony_ci if (memcpy_s(stashBuffer_.buffer + stashDataSize_, copyLen, buffer.buffer + writeSize, copyLen) != EOK) { 176fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 177fb299fa2Sopenharmony_ci } 178fb299fa2Sopenharmony_ci 179fb299fa2Sopenharmony_ci if (flowStream->Write(stashBuffer_, STASH_BUFFER_SIZE, start - stashDataSize_) != USCRIPT_SUCCESS) { 180fb299fa2Sopenharmony_ci LOG(ERROR) << "UnCompress flowStream write fail"; 181fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 182fb299fa2Sopenharmony_ci } 183fb299fa2Sopenharmony_ci writeSize += copyLen; 184fb299fa2Sopenharmony_ci stashDataSize_ = 0; 185fb299fa2Sopenharmony_ci } 186fb299fa2Sopenharmony_ci 187fb299fa2Sopenharmony_ci copyLen = size - writeSize; 188fb299fa2Sopenharmony_ci if (memcpy_s(stashBuffer_.buffer + stashDataSize_, copyLen, buffer.buffer + writeSize, copyLen) != EOK) { 189fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 190fb299fa2Sopenharmony_ci } 191fb299fa2Sopenharmony_ci stashDataSize_ += copyLen; 192fb299fa2Sopenharmony_ci if (stashDataSize_ == STASH_BUFFER_SIZE) { 193fb299fa2Sopenharmony_ci if (flowStream->Write(stashBuffer_, stashDataSize_, start - stashDataSize_ + copyLen) != USCRIPT_SUCCESS) { 194fb299fa2Sopenharmony_ci LOG(ERROR) << "UnCompress flowStream write fail"; 195fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 196fb299fa2Sopenharmony_ci } 197fb299fa2Sopenharmony_ci stashDataSize_ = 0; 198fb299fa2Sopenharmony_ci } 199fb299fa2Sopenharmony_ci return PKG_SUCCESS; 200fb299fa2Sopenharmony_ci} 201fb299fa2Sopenharmony_ci 202fb299fa2Sopenharmony_ciint32_t UScriptInstructionBinFlowWrite::ProcessBinFile(Uscript::UScriptEnv &env, Uscript::UScriptContext &context, 203fb299fa2Sopenharmony_ci PkgManager::StreamPtr stream) 204fb299fa2Sopenharmony_ci{ 205fb299fa2Sopenharmony_ci if (stream == nullptr) { 206fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get file stream"; 207fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 208fb299fa2Sopenharmony_ci } 209fb299fa2Sopenharmony_ci ON_SCOPE_EXIT(failExecute) { 210fb299fa2Sopenharmony_ci isStopRun_ = true; 211fb299fa2Sopenharmony_ci stream->Stop(); 212fb299fa2Sopenharmony_ci }; 213fb299fa2Sopenharmony_ci std::string pkgFileName; 214fb299fa2Sopenharmony_ci int32_t ret = context.GetParam(0, pkgFileName); 215fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 216fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get pkgFileName"; 217fb299fa2Sopenharmony_ci return ret; 218fb299fa2Sopenharmony_ci } 219fb299fa2Sopenharmony_ci 220fb299fa2Sopenharmony_ci LOG(INFO) << "UScriptInstructionBinFlowWrite::Execute " << pkgFileName; 221fb299fa2Sopenharmony_ci PkgManager::PkgManagerPtr manager = env.GetPkgManager(); 222fb299fa2Sopenharmony_ci if (manager == nullptr) { 223fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get pkg manager"; 224fb299fa2Sopenharmony_ci return USCRIPT_INVALID_PARAM; 225fb299fa2Sopenharmony_ci } 226fb299fa2Sopenharmony_ci std::vector<std::string> innerFileNames; 227fb299fa2Sopenharmony_ci ret = manager->LoadPackageWithStream(pkgFileName, Utils::GetCertName(), 228fb299fa2Sopenharmony_ci innerFileNames, PkgFile::PKG_TYPE_UPGRADE, stream); 229fb299fa2Sopenharmony_ci if (ret != USCRIPT_SUCCESS) { 230fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to load flow data stream"; 231fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 232fb299fa2Sopenharmony_ci } 233fb299fa2Sopenharmony_ci 234fb299fa2Sopenharmony_ci for (const auto &iter : innerFileNames) { 235fb299fa2Sopenharmony_ci // 根据镜像名称获取分区名称和大小 236fb299fa2Sopenharmony_ci std::string partitionName = iter; 237fb299fa2Sopenharmony_ci const FileInfo *info = manager->GetFileInfo(partitionName); 238fb299fa2Sopenharmony_ci if (info == nullptr) { 239fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to get file info"; 240fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 241fb299fa2Sopenharmony_ci } 242fb299fa2Sopenharmony_ci 243fb299fa2Sopenharmony_ci LOG(INFO) << " start process Component " << partitionName << " unpackedSize " << info->unpackedSize; 244fb299fa2Sopenharmony_ci if (ComponentProcess(env, stream, partitionName, *info) != USCRIPT_SUCCESS) { 245fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to process " << partitionName; 246fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 247fb299fa2Sopenharmony_ci } 248fb299fa2Sopenharmony_ci } 249fb299fa2Sopenharmony_ci CANCEL_SCOPE_EXIT_GUARD(failExecute); 250fb299fa2Sopenharmony_ci LOG(INFO)<<"UScriptInstructionBinFlowWrite finish"; 251fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 252fb299fa2Sopenharmony_ci} 253fb299fa2Sopenharmony_ci 254fb299fa2Sopenharmony_cibool UScriptInstructionBinFlowWrite::IsMatchedCsEsIamge(const Hpackage::FileInfo &fileInfo) 255fb299fa2Sopenharmony_ci{ 256fb299fa2Sopenharmony_ci if ((fileInfo.resType == ES_IMAGE && !Utils::IsEsDevice()) || 257fb299fa2Sopenharmony_ci (fileInfo.resType == CS_IMAGE && Utils::IsEsDevice())) { 258fb299fa2Sopenharmony_ci LOG(INFO) << "not matched cs es image, skip write"; 259fb299fa2Sopenharmony_ci return false; 260fb299fa2Sopenharmony_ci } 261fb299fa2Sopenharmony_ci return true; 262fb299fa2Sopenharmony_ci} 263fb299fa2Sopenharmony_ci 264fb299fa2Sopenharmony_cibool UScriptInstructionBinFlowWrite::CheckEsDeviceUpdate(const Hpackage::FileInfo &fileInfo) 265fb299fa2Sopenharmony_ci{ 266fb299fa2Sopenharmony_ci if (fileInfo.resType == NEED_VERIFY_CS_IMAGE && Utils::IsEsDevice()) { 267fb299fa2Sopenharmony_ci LOG(ERROR) << "pkg just cs image, but device is es"; 268fb299fa2Sopenharmony_ci return false; 269fb299fa2Sopenharmony_ci } 270fb299fa2Sopenharmony_ci return true; 271fb299fa2Sopenharmony_ci} 272fb299fa2Sopenharmony_ci 273fb299fa2Sopenharmony_ciint32_t UScriptInstructionBinFlowWrite::ComponentProcess(Uscript::UScriptEnv &env, PkgManager::StreamPtr stream, 274fb299fa2Sopenharmony_ci const std::string &name, const Hpackage::FileInfo &fileInfo) 275fb299fa2Sopenharmony_ci{ 276fb299fa2Sopenharmony_ci size_t fileSize = fileInfo.unpackedSize; 277fb299fa2Sopenharmony_ci // 根据镜像名获取组件处理类名 278fb299fa2Sopenharmony_ci std::unique_ptr<ComponentProcessor> processor = 279fb299fa2Sopenharmony_ci ComponentProcessorFactory::GetInstance().GetProcessor(name, fileSize); 280fb299fa2Sopenharmony_ci 281fb299fa2Sopenharmony_ci if (env.IsRetry()) { 282fb299fa2Sopenharmony_ci LOG(DEBUG) << "Retry updater, check if current partition updated already during last time"; 283fb299fa2Sopenharmony_ci bool isUpdated = PartitionRecord::GetInstance().IsPartitionUpdated(name); 284fb299fa2Sopenharmony_ci if (isUpdated) { 285fb299fa2Sopenharmony_ci LOG(INFO) << name << " already updated, skip"; 286fb299fa2Sopenharmony_ci processor.reset(); 287fb299fa2Sopenharmony_ci processor = std::make_unique<SkipImgProcessor>(name, fileSize); 288fb299fa2Sopenharmony_ci } 289fb299fa2Sopenharmony_ci } 290fb299fa2Sopenharmony_ci 291fb299fa2Sopenharmony_ci if (!CheckEsDeviceUpdate(fileInfo)) { 292fb299fa2Sopenharmony_ci LOG(ERROR) << "pkg just cs image, es device not allow update"; 293fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 294fb299fa2Sopenharmony_ci } 295fb299fa2Sopenharmony_ci 296fb299fa2Sopenharmony_ci if ((processor == nullptr && fileInfo.resType == UPGRADE_FILE_COMP_OTHER_TPYE) || 297fb299fa2Sopenharmony_ci !IsMatchedCsEsIamge(fileInfo)) { 298fb299fa2Sopenharmony_ci LOG(INFO) << name << " comp is not register and comp file is not image, or not match cs es image, skip"; 299fb299fa2Sopenharmony_ci processor.reset(); 300fb299fa2Sopenharmony_ci processor = std::make_unique<SkipImgProcessor>(name, fileSize); 301fb299fa2Sopenharmony_ci } 302fb299fa2Sopenharmony_ci 303fb299fa2Sopenharmony_ci if (processor == nullptr) { 304fb299fa2Sopenharmony_ci LOG(ERROR) << "GetProcessor failed, partition name: " << name; 305fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 306fb299fa2Sopenharmony_ci } 307fb299fa2Sopenharmony_ci processor->SetPkgFileInfo(stream->GetReadOffset(), stream->GetFileLength(), fullUpdateProportion_); 308fb299fa2Sopenharmony_ci LOG(INFO) << "component read offset " << stream->GetReadOffset(); 309fb299fa2Sopenharmony_ci 310fb299fa2Sopenharmony_ci if (processor->PreProcess(env) != USCRIPT_SUCCESS) { 311fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to PreProcess " << name; 312fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 313fb299fa2Sopenharmony_ci } 314fb299fa2Sopenharmony_ci 315fb299fa2Sopenharmony_ci if (processor->DoProcess(env) != USCRIPT_SUCCESS) { 316fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to DoProcess " << name; 317fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 318fb299fa2Sopenharmony_ci } 319fb299fa2Sopenharmony_ci 320fb299fa2Sopenharmony_ci if (processor->PostProcess(env) != USCRIPT_SUCCESS) { 321fb299fa2Sopenharmony_ci LOG(ERROR) << "Error to PostProcess " << name; 322fb299fa2Sopenharmony_ci return USCRIPT_ERROR_EXECUTE; 323fb299fa2Sopenharmony_ci } 324fb299fa2Sopenharmony_ci 325fb299fa2Sopenharmony_ci return USCRIPT_SUCCESS; 326fb299fa2Sopenharmony_ci} 327fb299fa2Sopenharmony_ci} // namespace Updater 328