From 9660931ae9676327cddecf7ca78f6ad0390e5f12 Mon Sep 17 00:00:00 2001 From: ldy Date: Sun, 20 Jul 2025 08:04:09 +0000 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B7=AE=E5=88=86=E5=90=8Esy?= =?UTF-8?q?nc=E7=9A=84=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ldy --- services/updater_binary/update_image_block.cpp | 16 ++++++++++++++-- services/updater_binary/update_image_block.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index a37187bf..7d43e499 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -43,7 +43,7 @@ constexpr int32_t SHA_CHECK_TARGETPAIRS_INDEX = 3; constexpr int32_t SHA_CHECK_TARGETSHA_INDEX = 4; constexpr int32_t SHA_CHECK_TARGET_PARAMS = 5; -__attribute__((weak)) void GetWriteDevPath(const std::string &path, [[maybe_unused]]const std::string &partitionName, +__attribute__((weak)) void GetWriteDevPath(const std::string &path, [[maybe_unused]] const std::string &partitionName, std::string &devPath) { devPath = path; @@ -51,6 +51,18 @@ __attribute__((weak)) void GetWriteDevPath(const std::string &path, [[maybe_unus return; } +__attribute__((weak)) void SyncWriteDevPath(int fd, [[maybe_unused]] const std::string &partitionName) +{ + if (fd < 0) { + LOG(ERROR) << "fd is invalid"; + return; + } + if (fsync(fd) == -1) { + LOG(ERROR) << "fsync failed for " << partitionName; + } + return; +} + static int ExtractNewData(const PkgBuffer &buffer, size_t size, size_t start, bool isFinish, const void* context) { void *p = const_cast(context); @@ -303,7 +315,7 @@ static int32_t DoExecuteUpdateBlock(const UpdateBlockInfo &infos, TransferManage return USCRIPT_ERROR_EXECUTE; } int32_t ret = ExecuteTransferCommand(fd, lines, tm, context, infos); - fsync(fd); + SyncWriteDevPath(fd, infos.partitionName); close(fd); fd = -1; env->GetPkgManager()->ClosePkgStream(outStream); diff --git a/services/updater_binary/update_image_block.h b/services/updater_binary/update_image_block.h index a8c192f8..e1261feb 100644 --- a/services/updater_binary/update_image_block.h +++ b/services/updater_binary/update_image_block.h @@ -73,6 +73,7 @@ extern "C" { #endif /* __cplusplus */ void GetWriteDevPath(const std::string &path, [[maybe_unused]]const std::string &partitionName, std::string &devPath); +void SyncWriteDevPath(int fd, [[maybe_unused]] const std::string &partitionName); #ifdef __cplusplus #if __cplusplus } -- Gitee