From 0b42787a4f03044f128039a8b2c0c48185101ddd Mon Sep 17 00:00:00 2001 From: ma_nan Date: Sun, 26 Sep 2021 10:46:49 +0800 Subject: [PATCH 1/5] fix codestyle Signed-off-by: ma_nan --- services/applypatch/block_set.cpp | 2 +- services/applypatch/transfer_manager.cpp | 19 +++++++++++-------- .../include/applypatch/transfer_manager.h | 1 + services/ui/view.h | 2 +- .../updater_binary/update_image_block.cpp | 5 +++-- services/updater_main.cpp | 11 ++++++++++- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/services/applypatch/block_set.cpp b/services/applypatch/block_set.cpp index b1670a93..b267cfb7 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 8cfd67c2..00d88b48 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,16 @@ bool TransferManager::CommandsParser(int fd, const std::vector &con if (CheckResult(ret, cmd->GetCommandLine(), cmd->GetCommandType()) == false) { return false; } - + if (initBlock == 0) { + initBlock = globalParams->written; + } bool typeResult = cmd->GetCommandType() == CommandType::NEW || cmd->GetCommandType() == CommandType::IMGDIFF || - cmd->GetCommandType() == CommandType::BSDIFF; + cmd->GetCommandType() == CommandType::BSDIFF || + cmd->GetCommandType() == CommandType::ZERO; if (totalSize != 0 && globalParams->env != nullptr && typeResult) { - globalParams->env->PostMessage("set_progress", - std::to_string((float)globalParams->written / totalSize)); + globalParams->env->PostMessage("set_progress", + std::to_string((float)(globalParams->written - initBlock) / totalSize)); } LOG(INFO) << "Running command : " << cmd->GetArgumentByPos(0) << " success"; } @@ -112,7 +116,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 +125,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); diff --git a/services/include/applypatch/transfer_manager.h b/services/include/applypatch/transfer_manager.h index 4d63a04d..3231917f 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; }; diff --git a/services/ui/view.h b/services/ui/view.h index afde4bd4..0f8fa7e0 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 4e049fd2..cd042792 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 56d98839..d94b41d9 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 -- Gitee From 3246fd311ffd0e8775a2f5eacfe1c7f96709f5f7 Mon Sep 17 00:00:00 2001 From: ma_nan Date: Sun, 26 Sep 2021 10:49:32 +0800 Subject: [PATCH 2/5] delete extra code Signed-off-by: ma_nan --- .../include/sparse_image/sparse_image_api.h | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 services/include/sparse_image/sparse_image_api.h 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 210541e4..00000000 --- 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 -- Gitee From b5a7557512759b5ec2da54ab1ab47d11b41dfb92 Mon Sep 17 00:00:00 2001 From: ma_nan Date: Sun, 26 Sep 2021 14:57:17 +0800 Subject: [PATCH 3/5] fix codestyle Signed-off-by: ma_nan --- services/applypatch/transfer_manager.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/services/applypatch/transfer_manager.cpp b/services/applypatch/transfer_manager.cpp index 00d88b48..6ba2e13d 100644 --- a/services/applypatch/transfer_manager.cpp +++ b/services/applypatch/transfer_manager.cpp @@ -91,11 +91,7 @@ bool TransferManager::CommandsParser(int fd, const std::vector &con if (initBlock == 0) { initBlock = globalParams->written; } - bool typeResult = cmd->GetCommandType() == CommandType::NEW || - cmd->GetCommandType() == CommandType::IMGDIFF || - cmd->GetCommandType() == CommandType::BSDIFF || - cmd->GetCommandType() == CommandType::ZERO; - if (totalSize != 0 && globalParams->env != nullptr && typeResult) { + if (totalSize != 0 && globalParams->env != nullptr && NeedSetProgress(cmd->GetCommandType())) { globalParams->env->PostMessage("set_progress", std::to_string((float)(globalParams->written - initBlock) / totalSize)); } @@ -140,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) { -- Gitee From ec86db2b3ce3b1c814be9947adf85c77454afe6f Mon Sep 17 00:00:00 2001 From: ma_nan Date: Sun, 26 Sep 2021 14:59:39 +0800 Subject: [PATCH 4/5] fix codestyle Signed-off-by: ma_nan --- services/include/applypatch/transfer_manager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/include/applypatch/transfer_manager.h b/services/include/applypatch/transfer_manager.h index 3231917f..e654e2b7 100644 --- a/services/include/applypatch/transfer_manager.h +++ b/services/include/applypatch/transfer_manager.h @@ -73,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); -- Gitee From f4a85822b22d2077b61244e149a3318ade79b96d Mon Sep 17 00:00:00 2001 From: ma_nan Date: Sun, 26 Sep 2021 21:51:25 +0800 Subject: [PATCH 5/5] fix codestyle Signed-off-by: ma_nan --- services/include/applypatch/transfer_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/include/applypatch/transfer_manager.h b/services/include/applypatch/transfer_manager.h index e654e2b7..b2e06bdb 100644 --- a/services/include/applypatch/transfer_manager.h +++ b/services/include/applypatch/transfer_manager.h @@ -73,7 +73,7 @@ public: } std::string ReloadForRetry() const; bool CheckResult(const CommandResult result, const std::string &cmd, const CommandType &type); - bool NeedSetProgress(const CommandType &type); + bool NeedSetProgress(const CommandType &type); private: bool RegisterForRetry(const std::string &cmd); -- Gitee