From 4a74f574ff4241613a9e8ece5d1048115db0ee0e Mon Sep 17 00:00:00 2001 From: ma_nan Date: Wed, 8 Sep 2021 15:19:34 +0800 Subject: [PATCH 1/3] fix codestyle Signed-off-by: ma_nan --- services/applypatch/partition_record.cpp | 8 ++++---- services/applypatch/transfer_manager.cpp | 17 ++++++++++------- services/include/applypatch/partition_record.h | 4 ++-- services/ui/text_label.cpp | 16 ++++++++-------- services/ui/text_label.h | 4 ++++ 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/services/applypatch/partition_record.cpp b/services/applypatch/partition_record.cpp index 9d758176..f00aea61 100644 --- a/services/applypatch/partition_record.cpp +++ b/services/applypatch/partition_record.cpp @@ -31,9 +31,9 @@ bool PartitionRecord::IsPartitionUpdated(const std::string &partitionName) { auto miscBlockDevice = GetMiscPartitionPath(); uint8_t buffer[PARTITION_UPDATER_RECORD_MSG_SIZE]; - char *realPath = realpath(miscBlockDevice.c_str(), NULL); - UPDATER_FILE_CHECK(realPath != nullptr, "realPath is NULL", return false); if (!miscBlockDevice.empty()) { + char *realPath = realpath(miscBlockDevice.c_str(), NULL); + UPDATER_FILE_CHECK(realPath != nullptr, "realPath is NULL", return false); int fd = open(realPath, O_RDONLY | O_EXCL | O_CLOEXEC | O_BINARY); free(realPath); UPDATER_FILE_CHECK(fd >= 0, "PartitionRecord: Open misc to recording partition failed", return false); @@ -60,9 +60,9 @@ bool PartitionRecord::IsPartitionUpdated(const std::string &partitionName) bool PartitionRecord::RecordPartitionUpdateStatus(const std::string &partitionName, bool updated) { auto miscBlockDevice = GetMiscPartitionPath(); - char *realPath = realpath(miscBlockDevice.c_str(), NULL); - UPDATER_FILE_CHECK(realPath != nullptr, "realPath is NULL", return false); if (!miscBlockDevice.empty()) { + char *realPath = realpath(miscBlockDevice.c_str(), NULL); + UPDATER_FILE_CHECK(realPath != nullptr, "realPath is NULL", return false); int fd = open(realPath, O_RDWR | O_EXCL | O_CLOEXEC | O_BINARY); free(realPath); UPDATER_FILE_CHECK(fd >= 0, "PartitionRecord: Open misc to recording partition failed", return false); diff --git a/services/applypatch/transfer_manager.cpp b/services/applypatch/transfer_manager.cpp index bb2746c1..e98cddb5 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); @@ -82,18 +83,21 @@ bool TransferManager::CommandsParser(int fd, const std::vector &con cmd->SetFileDescriptor(fd); std::unique_ptr cf = CommandFunctionFactory::GetCommandFunction(cmd->GetCommandType()); UPDATER_ERROR_CHECK(cf != nullptr, "Failed to get cmd exec", return false); - CommandResult ret = cf->Execute(const_cast(*cmd.get())); + CommandResult ret = cf->Execute(const_cast(*cmd.get())); CommandFunctionFactory::ReleaseCommandFunction(cf); 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"; } @@ -121,7 +125,6 @@ bool TransferManager::RegisterForRetry(const std::string &cmd) UPDATER_ERROR_CHECK_NOT_RETURN(ret, "Write retry flag error"); fsync(fd); close(fd); - return ret; } diff --git a/services/include/applypatch/partition_record.h b/services/include/applypatch/partition_record.h index 916863f4..d3418992 100644 --- a/services/include/applypatch/partition_record.h +++ b/services/include/applypatch/partition_record.h @@ -72,7 +72,7 @@ private: // offset of partition record in misc. // offset is not start from zero, but // start from the global offset of misc partition. - size_t offset_; + off_t offset_; }; } // namespace updater -#endif // UPDATER_PARTITION_UPDATE_RECORD_H \ No newline at end of file +#endif // UPDATER_PARTITION_UPDATE_RECORD_H diff --git a/services/ui/text_label.cpp b/services/ui/text_label.cpp index 0b87320e..0c1343b3 100644 --- a/services/ui/text_label.cpp +++ b/services/ui/text_label.cpp @@ -101,8 +101,7 @@ void TextLabel::InitFont() png_structp fontPngPtr = nullptr; int fontBitDepth = 0; int fontColorType = 0; - uint32_t offset = 2; - UPDATER_CHECK_ONLY_RETURN(!memset_s(resPath, MAX_TEXT_SIZE + offset, 0, MAX_TEXT_SIZE + 1), return); + UPDATER_CHECK_ONLY_RETURN(!memset_s(resPath, MAX_TEXT_SIZE + offset_, 0, MAX_TEXT_SIZE + 1), return); switch (fontType_) { case DEFAULT_FONT: UPDATER_CHECK_ONLY_RETURN(snprintf_s(resPath, sizeof(resPath), sizeof(resPath) -1, "/resources/%s.png", @@ -115,8 +114,7 @@ void TextLabel::InitFont() } FILE* fp = fopen(resPath, "rb"); UPDATER_ERROR_CHECK(fp, "open font failed!", return); - const int headerNumber = 8; - uint8_t header[headerNumber]; + uint8_t header[headerNumber_]; size_t bytesRead = fread(header, 1, sizeof(header), fp); UPDATER_ERROR_CHECK(bytesRead == sizeof(header), "read header failed!", fclose(fp); return); if (png_sig_cmp(header, 0, sizeof(header))) { @@ -135,14 +133,16 @@ void TextLabel::InitFont() png_get_IHDR(fontPngPtr, fontInfoPtr, &fontWidth, &fontHeight, &fontBitDepth, &fontColorType, nullptr, nullptr, nullptr); fontChannels = png_get_channels(fontPngPtr, fontInfoPtr); - const int defaultFontBitDepth = 8; - if (fontBitDepth <= defaultFontBitDepth && fontChannels == 1 && fontColorType == PNG_COLOR_TYPE_GRAY) { + if (fontBitDepth <= defaultFontBitDepth_ && fontChannels == 1 && fontColorType == PNG_COLOR_TYPE_GRAY) { png_set_expand_gray_1_2_4_to_8(fontPngPtr); } - const int defaultFontWidth = 96; - fontWidth_ = fontWidth / defaultFontWidth; + fontWidth_ = fontWidth / defaultFontWidth_; fontHeight_ = fontHeight >> 1; PNGReadRow(fontWidth_, fontHeight_, fontPngPtr, fontBuf_); + if (fp != nullptr) { + fclose(fp); + fp = nullptr; + } } void TextLabel::SetText(const char *str) diff --git a/services/ui/text_label.h b/services/ui/text_label.h index 39f4d1b2..82d5fb9a 100644 --- a/services/ui/text_label.h +++ b/services/ui/text_label.h @@ -75,6 +75,10 @@ private: char fontBuf_[MAX_FONT_BUFFER_SIZE_HW * FONT_BUFFER_SIZE] {}; unsigned int fontWidth_ = 0; unsigned int fontHeight_ = 0; + uint32_t offset_ = 2; + const int defaultFontWidth_ = 96; + const int defaultFontBitDepth_ = 8; + const int headerNumber_ = 8; }; } // namespace updater #endif -- Gitee From b1845866570655235161801f655e1456571062a7 Mon Sep 17 00:00:00 2001 From: ma_nan Date: Wed, 8 Sep 2021 15:28:41 +0800 Subject: [PATCH 2/3] fix codestyle Signed-off-by: ma_nan --- services/updater_main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 edf419ce304ae1b2a428384256ea8f37bef1d72a Mon Sep 17 00:00:00 2001 From: ma_nan Date: Wed, 8 Sep 2021 20:08:25 +0800 Subject: [PATCH 3/3] fix codestyle Signed-off-by: ma_nan --- services/ui/drm_driver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ui/drm_driver.h b/services/ui/drm_driver.h index 62b5385f..d12b6742 100644 --- a/services/ui/drm_driver.h +++ b/services/ui/drm_driver.h @@ -51,7 +51,7 @@ private: int fd_; drmModeConnector *conn_; drmModeRes *res_; - struct BufferObject buff_; + struct BufferObject buff_ {}; }; } // namespace updater #endif -- Gitee