From f2e85da49edf3b4d9a6b4f4fc8fd9706aeed9061 Mon Sep 17 00:00:00 2001 From: gwx1278443 Date: Sun, 4 Feb 2024 15:41:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E8=87=AA=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gwx1278443 --- .../src/mod_fs/class_watcher/watcher_entity.cpp | 3 +-- .../kits/js/src/mod_fs/properties/copy.cpp | 17 +++++++++-------- interfaces/kits/js/src/mod_fs/properties/copy.h | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp index 64a27c55d..f648026d3 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp @@ -188,9 +188,8 @@ void FileWatcher::GetNotifyEvent(WatcherCallback callback) fds[0].events = 0; fds[1].fd = notifyFd_; fds[1].events = POLLIN; - int ret = 0; while (run_) { - ret = poll(fds, nfds, -1); + int ret = poll(fds, nfds, -1); if (ret > 0) { if (fds[0].revents & POLLNVAL) { run_ = false; diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index f485c96bf..c7a7abf0b 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -266,7 +266,7 @@ std::string Copy::GetRealPath(const std::string& path) return realPath.string(); } -uint64_t Copy::GetDirSize(std::shared_ptr infos, std::string path) +uint64_t Copy::GetDirSize(std::shared_ptr infos, const std::string &path) { unique_ptr pNameList = { new (nothrow) struct NameList, Deleter }; if (pNameList == nullptr) { @@ -523,10 +523,11 @@ void Copy::OnFileReceive(std::shared_ptr infos) std::shared_ptr Copy::GetReceivedInfo(int wd, std::shared_ptr callback) { - for (auto &it : callback->wds) { - if (it.first == wd) { - return it.second; - } + auto it = find_if(callback->wds.begin(), callback->wds.end(), [wd](const auto& item) { + return item.first == wd; + }); + if (it != callback->wds.end()) { + return it->second; } return nullptr; } @@ -676,7 +677,7 @@ std::string Copy::ConvertUriToPath(const std::string &uri) } tuple> Copy::CreateFileInfos( - const std::string &srcUri, const std::string &destUri, NVal &listener) + const std::string &srcUri, const std::string &destUri, const NVal &listener) { auto infos = CreateSharedPtr(); if (infos == nullptr) { @@ -710,11 +711,11 @@ int Copy::ExecCopy(std::shared_ptr infos) { if (IsFile(infos->srcPath) && IsFile(infos->destPath)) { // copyFile - return CopyFile(infos->srcPath.c_str(), infos->destPath.c_str()); + return CopyFile(infos->srcPath, infos->destPath); } if (IsDirectory(infos->srcPath) && IsDirectory(infos->destPath)) { // copyDir - return CopyDirFunc(infos->srcPath.c_str(), infos->destPath.c_str(), infos); + return CopyDirFunc(infos->srcPath, infos->destPath, infos); } return EINVAL; } diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.h b/interfaces/kits/js/src/mod_fs/properties/copy.h index 90200a899..a30c42710 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.h +++ b/interfaces/kits/js/src/mod_fs/properties/copy.h @@ -113,7 +113,7 @@ class Copy final { public: static napi_value Async(napi_env env, napi_callback_info info); static std::map> jsCbMap_; - static void UnregisterListener(std::shared_ptr fileInfos); + static void UnregisterListener(std::shared_ptr infos); static std::recursive_mutex mutex_; private: @@ -141,13 +141,13 @@ private: // operator of file static int RecurCopyDir(const string &srcPath, const string &destPath, std::shared_ptr infos); static tuple GetFileSize(const std::string &path); - static uint64_t GetDirSize(std::shared_ptr infos, std::string path); + static uint64_t GetDirSize(std::shared_ptr infos, const std::string &path); static int CopyFile(const string &src, const string &dest); static int MakeDir(const string &path); static int CopySubDir(const string &srcPath, const string &destPath, std::shared_ptr infos); static int CopyDirFunc(const string &src, const string &dest, std::shared_ptr infos); static tuple> CreateFileInfos( - const std::string &srcUri, const std::string &destUri, NVal &listener); + const std::string &srcUri, const std::string &destUri, const NVal &listener); static int ExecCopy(std::shared_ptr infos); // operator of file size @@ -171,4 +171,4 @@ private: } // namespace FileManagement } // namespace OHOS -#endif // FILEMANAGEMENT_FILE_API_COPY_H +#endif // FILEMANAGEMENT_FILE_API_COPY_H \ No newline at end of file -- Gitee