From de0f56ff417415fe55e5a16eb4b9b63742c8c9ac Mon Sep 17 00:00:00 2001 From: oh_ci Date: Tue, 19 Nov 2024 12:04:13 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!7237=20?= =?UTF-8?q?:=20fsync=E6=89=80=E6=9C=89=E7=B1=BB=E5=9E=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/installd/installd_operator.h | 2 +- services/bundlemgr/src/base_extractor.cpp | 1 + .../src/installd/installd_operator.cpp | 22 ++++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/services/bundlemgr/include/installd/installd_operator.h b/services/bundlemgr/include/installd/installd_operator.h index f9d84983a4..92f0d32de3 100644 --- a/services/bundlemgr/include/installd/installd_operator.h +++ b/services/bundlemgr/include/installd/installd_operator.h @@ -330,7 +330,7 @@ private: static EnforceMetadataProcessForApp enforceMetadataProcessForApp_; static bool OpenEncryptionHandle(); #endif - static void FsyncFile(const std::string &path); + static void FsyncResFile(const std::string &path, const ExtractFileType &extractFileType); static std::string GetSameLevelTmpPath(const std::string &path); }; } // namespace AppExecFwk diff --git a/services/bundlemgr/src/base_extractor.cpp b/services/bundlemgr/src/base_extractor.cpp index 5de271dec5..66f231b4a6 100644 --- a/services/bundlemgr/src/base_extractor.cpp +++ b/services/bundlemgr/src/base_extractor.cpp @@ -104,6 +104,7 @@ bool BaseExtractor::ExtractFile(const std::string &fileName, const std::string & } return false; } + fileStream.flush(); fileStream.clear(); fileStream.close(); return true; diff --git a/services/bundlemgr/src/installd/installd_operator.cpp b/services/bundlemgr/src/installd/installd_operator.cpp index 7e4ef79ad3..1fb9635d33 100644 --- a/services/bundlemgr/src/installd/installd_operator.cpp +++ b/services/bundlemgr/src/installd/installd_operator.cpp @@ -617,21 +617,23 @@ void InstalldOperator::ExtractTargetFile(const BundleExtractor &extractor, const LOG_E(BMS_TAG_INSTALLD, "ChangeModeFile %{public}s failed, errno: %{public}d", path.c_str(), errno); return; } - FsyncFile(path); + FsyncResFile(path, extractFileType); LOG_D(BMS_TAG_INSTALLD, "extract file success, path : %{public}s", path.c_str()); } -void InstalldOperator::FsyncFile(const std::string &path) +void InstalldOperator::FsyncResFile(const std::string &path, const ExtractFileType &extractFileType) { - int32_t fileFd = open(path.c_str(), O_RDONLY); - if (fileFd < 0) { - LOG_E(BMS_TAG_INSTALLER, "open %{public}s failed %{public}d", path.c_str(), errno); - return; - } - if (fsync(fileFd) != 0) { - LOG_E(BMS_TAG_INSTALLER, "fsync %{public}s failed %{public}d", path.c_str(), errno); + if (extractFileType == ExtractFileType::RES_FILE) { + int32_t fileFd = open(path.c_str(), O_RDONLY); + if (fileFd < 0) { + LOG_E(BMS_TAG_INSTALLER, "open %{public}s failed", path.c_str()); + return; + } + if (fsync(fileFd) != 0) { + LOG_E(BMS_TAG_INSTALLER, "fsync %{public}s failed", path.c_str()); + } + close(fileFd); } - close(fileFd); } bool InstalldOperator::DeterminePrefix(const ExtractFileType &extractFileType, const std::string &cpuAbi, -- Gitee