diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 04f197a6366fc27a7726435d13dd4de8ecf241b2..ac4e08ab1c686b52bc73bcec6365ef3ce2e36246 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -548,6 +548,7 @@ PkgEntryPtr PkgManagerImpl::GetPkgEntry(const std::string &path) PkgManager::StreamPtr PkgManagerImpl::GetPkgFileStream(const std::string &fileName) { + std::lock_guard lock(mapLock_); auto iter = pkgStreams_.find(fileName); if (iter != pkgStreams_.end()) { return (*iter).second; diff --git a/services/ptable_parse/ptable.h b/services/ptable_parse/ptable.h index 654e10d80179d4e2a53f89356d7e9687581d11d3..fb29fe595e62898e69225c6167e4efd54cd398af 100644 --- a/services/ptable_parse/ptable.h +++ b/services/ptable_parse/ptable.h @@ -82,7 +82,7 @@ public: std::vector& GetPtablePartitionInfoInstance(); bool LoadPtnInfo(const std::vector& ptnInfo); bool ReadPartitionFileToBuffer(uint8_t *ptbImgBuffer, uint32_t &imgBufSize); - void DeletePartitionTmpFile(); + static void DeletePartitionTmpFile(); virtual bool WritePartitionBufToFile(uint8_t *ptbImgBuffer, const uint32_t imgBufSize); virtual bool ParsePartitionFromBuffer(uint8_t *ptbImgBuffer, const uint32_t imgBufSize) = 0; diff --git a/services/ptable_parse/ptable_manager.cpp b/services/ptable_parse/ptable_manager.cpp index 2534f1835df56acfbfe3371cc60dfa74163a7bb9..438db6ada678c61e1951b974adefcfc2033f6736 100644 --- a/services/ptable_parse/ptable_manager.cpp +++ b/services/ptable_parse/ptable_manager.cpp @@ -334,24 +334,24 @@ bool PtableManager::WritePtableWithFile() { if (pPtable_ == nullptr) { LOG(ERROR) << "pPtable_ is nullptr"; - pPtable_->DeletePartitionTmpFile(); + Ptable::DeletePartitionTmpFile(); return true; } if (!LoadPartitionInfoWithFile()) { LOG(ERROR) << "load partition info with file fail"; - pPtable_->DeletePartitionTmpFile(); + Ptable::DeletePartitionTmpFile(); return true; } #ifndef UPDATER_UT if (!pPtable_->WritePartitionTable()) { LOG(ERROR) << "Write ptable to device failed! Please load ptable first!"; - pPtable_->DeletePartitionTmpFile(); + Ptable::DeletePartitionTmpFile(); return false; } #endif - pPtable_->DeletePartitionTmpFile(); + Ptable::DeletePartitionTmpFile(); LOG(INFO) << "write patble with file success"; return true; } diff --git a/utils/utils_fs.cpp b/utils/utils_fs.cpp index d14497f38edebfb8452a445742277c3268946671..9a730c03e6a18333720702deeab0b2064de808f0 100644 --- a/utils/utils_fs.cpp +++ b/utils/utils_fs.cpp @@ -77,7 +77,11 @@ int64_t GetFilesFromDirectory(const std::string &path, std::vector return -1; } DIR *dirp = opendir(path.c_str()); - struct dirent *dp; + if (dirp == nullptr) { + LOG(ERROR) << "Failed to opendir errno=" << errno; + return -1; + } + struct dirent *dp = nullptr; int64_t totalSize = 0; while ((dp = readdir(dirp)) != nullptr) { std::string fileName = path + "/" + dp->d_name; @@ -95,6 +99,7 @@ int64_t GetFilesFromDirectory(const std::string &path, std::vector } } closedir(dirp); + dirp = nullptr; return totalSize; }