diff --git a/services/bundlemgr/include/installd/installd_operator.h b/services/bundlemgr/include/installd/installd_operator.h index f9d84983a430f36577102c497fe814ff945eaab5..92f0d32de309d2cb81857bd0734d2659073244a3 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 5de271dec5ed73bec7c166fcd4810bce546ad2df..66f231b4a65628ad7a8ab8516b82216744577f23 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 7e4ef79ad347da0db41d51dcfa271e6bf9151d9a..1fb9635d33cfcaffa8a0fd2f5bcecf1bfe4f2b57 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,