diff --git a/services/applypatch/partition_record.cpp b/services/applypatch/partition_record.cpp index 9d7581762a1b1eb150de742286d0a961c78b0514..f00aea61dfc8d2c89d4c6faa135387f37e3f3425 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 bb2746c1b9b9a4ebbc5fd1406b4ec699d3c8352a..e98cddb5db90ffef5894941b129b9379f75f7e34 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 916863f45de28cf357cdddb2aa830e24ba7cc3ca..d3418992de8a58936e927264b25fb5fb5cd934e9 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/drm_driver.h b/services/ui/drm_driver.h index 62b5385f20d2e1c46cd937ee40352b6278025348..d12b67420f4786995803714088753996a8c2b1f5 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 diff --git a/services/ui/text_label.cpp b/services/ui/text_label.cpp index 0b87320efa3ef56d6de6111871c1debdf25d2f36..0c1343b32418659dddb4f92afaeb48e126a0f651 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 39f4d1b2000935c08b18b73745e0a92c2021d77b..82d5fb9a4cb04df8b185a9b72630701f817487c9 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 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