diff --git a/services/applypatch/block_set.cpp b/services/applypatch/block_set.cpp index b1670a933cf21730069449cd4431a5ed674b67b4..b267cfb72a0f6bb955690fadd313cef42ad6c332 100644 --- a/services/applypatch/block_set.cpp +++ b/services/applypatch/block_set.cpp @@ -228,7 +228,7 @@ int32_t BlockSet::LoadSourceBuffer(const Command &cmd, size_t &pos, std::vector< LOG(INFO) << "new start to read source block ..."; UPDATER_CHECK_ONLY_RETURN(srcBlk.ReadDataFromBlock(cmd.GetFileDescriptor(), sourceBuffer) > 0, return -1); std::string nextArgv = cmd.GetArgumentByPos(pos++); - UPDATER_CHECK_ONLY_RETURN(nextArgv != "", return 0); + UPDATER_CHECK_ONLY_RETURN(nextArgv != "", return 1); BlockSet locations; locations.ParserAndInsert(nextArgv); MoveBlock(sourceBuffer, locations, sourceBuffer); diff --git a/services/applypatch/transfer_manager.cpp b/services/applypatch/transfer_manager.cpp index 8cfd67c2e39ca88acd246abeccd83a359c1087b7..6ba2e13db99a2acbba140fb4c3ce6eed32a22dc9 100644 --- a/services/applypatch/transfer_manager.cpp +++ b/services/applypatch/transfer_manager.cpp @@ -58,12 +58,13 @@ bool TransferManager::CommandsParser(int fd, const std::vector &con globalParams->blockCount = utils::String2Int(*ct++, utils::N_DEC); globalParams->maxEntries = utils::String2Int(*ct++, utils::N_DEC); globalParams->maxBlocks = utils::String2Int(*ct++, utils::N_DEC); - size_t totalSize = globalParams->maxBlocks * globalParams->blockCount; + size_t totalSize = globalParams->blockCount; std::string retryCmd = ""; if (globalParams != nullptr && globalParams->env != nullptr && globalParams->env->IsRetry()) { retryCmd = ReloadForRetry(); } std::unique_ptr cmd; + int initBlock = 0; while (ct != context.end()) { cmd = std::make_unique(); UPDATER_ERROR_CHECK(cmd != nullptr, "Failed to parse command line.", return false); @@ -87,13 +88,12 @@ bool TransferManager::CommandsParser(int fd, const std::vector &con if (CheckResult(ret, cmd->GetCommandLine(), cmd->GetCommandType()) == false) { return false; } - - bool typeResult = cmd->GetCommandType() == CommandType::NEW || - cmd->GetCommandType() == CommandType::IMGDIFF || - cmd->GetCommandType() == CommandType::BSDIFF; - if (totalSize != 0 && globalParams->env != nullptr && typeResult) { - globalParams->env->PostMessage("set_progress", - std::to_string((float)globalParams->written / totalSize)); + if (initBlock == 0) { + initBlock = globalParams->written; + } + if (totalSize != 0 && globalParams->env != nullptr && NeedSetProgress(cmd->GetCommandType())) { + globalParams->env->PostMessage("set_progress", + std::to_string((float)(globalParams->written - initBlock) / totalSize)); } LOG(INFO) << "Running command : " << cmd->GetArgumentByPos(0) << " success"; } @@ -112,7 +112,7 @@ void TransferManager::Init() bool TransferManager::RegisterForRetry(const std::string &cmd) { - std::string path = globalParams->storeBase + "/" + "retry_flag"; + std::string path = globalParams->retryFile; int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); UPDATER_ERROR_CHECK(fd != -1, "Failed to create", return false); UPDATER_ERROR_CHECK(fchown(fd, O_USER_GROUP_ID, O_USER_GROUP_ID) == 0, @@ -121,13 +121,12 @@ bool TransferManager::RegisterForRetry(const std::string &cmd) UPDATER_ERROR_CHECK_NOT_RETURN(ret, "Write retry flag error"); fsync(fd); close(fd); - return ret; } std::string TransferManager::ReloadForRetry() const { - std::string path = globalParams->storeBase + "/" + "retry_flag"; + std::string path = globalParams->retryFile; int fd = open(path.c_str(), O_RDONLY); UPDATER_ERROR_CHECK(fd >= 0, "Failed to open", return ""); (void)lseek(fd, 0, SEEK_SET); @@ -137,6 +136,14 @@ std::string TransferManager::ReloadForRetry() const return cmd; } +bool TransferManager::NeedSetProgress(const CommandType &type) +{ + return type == CommandType::NEW || + type == CommandType::IMGDIFF || + type == CommandType::BSDIFF || + type == CommandType::ZERO; +} + bool TransferManager::CheckResult(const CommandResult result, const std::string &cmd, const CommandType &type) { switch (result) { diff --git a/services/include/applypatch/transfer_manager.h b/services/include/applypatch/transfer_manager.h index 4d63a04dc568f0f4a3ad7d2d0097577a520ba7a8..b2e06bdbad476b0bed2e25f537b587e6bce01ac2 100644 --- a/services/include/applypatch/transfer_manager.h +++ b/services/include/applypatch/transfer_manager.h @@ -50,6 +50,7 @@ struct TransferParams { std::unique_ptr writerThreadInfo; int storeCreated; std::string storeBase; + std::string retryFile; uint8_t *patchDataBuffer; size_t patchDataSize; }; @@ -72,6 +73,7 @@ public: } std::string ReloadForRetry() const; bool CheckResult(const CommandResult result, const std::string &cmd, const CommandType &type); + bool NeedSetProgress(const CommandType &type); private: bool RegisterForRetry(const std::string &cmd); diff --git a/services/include/sparse_image/sparse_image_api.h b/services/include/sparse_image/sparse_image_api.h deleted file mode 100644 index 210541e4e01ad6ce316f6261fda9a1ec2e700324..0000000000000000000000000000000000000000 --- a/services/include/sparse_image/sparse_image_api.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UPDATER_SPARSE_IMAGE_API_H -#define UPDATER_SPARSE_IMAGE_API_H -namespace updater { -// SparseImage structure is an internal structure of libsparseimage -// Just declare it here. -struct SparseImage; -struct SparseImage *CreateSparseImageFromBuffer(char *buff); -void DeallocateSparseImage(struct SparseImage *si); -int SparseImageRestore(int fd, struct SparseImage *si); -} // namespace updater -#endif // UPDATER_SPARSE_IMAGE_API_H diff --git a/services/ui/view.h b/services/ui/view.h index afde4bd484bb18afa1275e1d659d3f6daf4db657..0f8fa7e00522f0bccb7567e1685dff747fb69319 100644 --- a/services/ui/view.h +++ b/services/ui/view.h @@ -70,9 +70,9 @@ public: std::mutex mutex_; protected: void* CreateBuffer(int w, int h, int pixelFormat); -private: char* viewBuffer_ = nullptr; char* shadowBuffer_ = nullptr; +private: int bufferSize_ = 0; bool isVisiable_ = true; int viewId_ = 0; diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 4e049fd2bcdbed2766eb6484affa5dc8cc4b356b..cd042792d841272a5d5945ddbbc1e1496d55b8a5 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -167,13 +167,14 @@ static int32_t GetUpdateBlockInfo(struct UpdateBlockInfo &infos, uscript::UScrip } static int32_t ExecuteTransferCommand(int fd, const std::vector &lines, uscript::UScriptEnv &env, - uscript::UScriptContext &context) + uscript::UScriptContext &context, const std::string &partitionName) { TransferManagerPtr tm = TransferManager::GetTransferManagerInstance(); auto globalParams = tm->GetGlobalParams(); auto writerThreadInfo = globalParams->writerThreadInfo.get(); globalParams->storeBase = "/data/updater/update_tmp"; + globalParams->retryFile = std::string("/data/updater") + partitionName + "_retry"; LOG(INFO) << "Store base path is " << globalParams->storeBase; int32_t ret = Store::CreateNewSpace(globalParams->storeBase, !globalParams->env->IsRetry()); UPDATER_ERROR_CHECK(ret != -1, "Error to create new store space", @@ -247,7 +248,7 @@ static int32_t DoExecuteUpdateBlock(UpdateBlockInfo &infos, uscript::UScriptEnv int fd = open(infos.devPath.c_str(), O_RDWR | O_LARGEFILE); UPDATER_ERROR_CHECK (fd != -1, "Failed to open block", env.GetPkgManager()->ClosePkgStream(outStream); return USCRIPT_ERROR_EXECUTE); - int32_t ret = ExecuteTransferCommand(fd, lines, env, context); + int32_t ret = ExecuteTransferCommand(fd, lines, env, context, infos.partitionName); fsync(fd); close(fd); fd = -1; diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 56d98839b28db2385eef73fd5b250b04acffc936..d94b41d9af92e0a2e77c4c18f3aa6fc9db135f87 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -264,6 +264,15 @@ static UpdaterStatus StartUpdater(PkgManager::PkgManagerPtr manager, const std:: return StartUpdaterEntry(manager, args, upParams); } +static bool IsDir(const std::string &path) +{ + struct stat st{}; + if (stat(path.c_str(), &st) < 0) { + return false; + } + return S_ISDIR(st.st_mode); +} + static bool DeleteUpdaterPath(const std::string &path) { auto pDir = std::unique_ptr(opendir(path.c_str()), closedir); @@ -276,7 +285,7 @@ static bool DeleteUpdaterPath(const std::string &path) if (currentName[0] != '.' && (currentName.compare("log") != 0)) { std::string tmpName(path); tmpName.append("/" + currentName); - if (tmpName.find(".") == std::string::npos) { + if (IsDir(tmpName)) { DeleteUpdaterPath(tmpName); } #ifndef UPDATER_UT