From c2f4bc91649ae6b64c677f852f8780a799069502 Mon Sep 17 00:00:00 2001 From: h30051954 Date: Fri, 29 Dec 2023 14:56:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: h30051954 --- .../kits/js/src/mod_fs/properties/copy.cpp | 21 ++++++++++++++----- .../kits/js/src/mod_fs/properties/copy.h | 2 ++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index dedbcf812..05eaa127e 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -50,6 +50,7 @@ const string PROCEDURE_COPY_NAME = "FileFSCopy"; constexpr int DISMATCH = 0; constexpr int MATCH = 1; constexpr int BUF_SIZE = 1024; +constexpr std::chrono::milliseconds NOTIFY_PROGRESS_DELAY(200); std::recursive_mutex Copy::mutex_; std::map> Copy::jsCbMap_; @@ -129,7 +130,7 @@ tuple Copy::GetFileSize(const std::string &path) void Copy::CheckOrCreatePath(const std::string &destPath) { if (!filesystem::exists(destPath)) { - HILOGE("destPath not exist, destPath = %{public}s", destPath.c_str()); + HILOGI("destPath not exist, destPath = %{public}s", destPath.c_str()); ofstream out; out.open(destPath.c_str()); out.close(); @@ -283,7 +284,13 @@ int Copy::CopyDirFunc(const string &src, const string &dest, std::shared_ptr infos, std::shared_ptr callback) { - CheckOrCreatePath(infos->destPath); + if (infos->srcPath == infos->destPath) { + HILOGE("The src and dest are the same."); + return EINVAL; + } + if (IsFile(infos->srcPath)) { + CheckOrCreatePath(infos->destPath); + } if (!infos->hasListener) { return ExecCopy(infos); } @@ -387,7 +394,7 @@ void Copy::ReceiveComplete(uv_work_t *work, int stat) return; } auto processedSize = entry->progressSize; - if (processedSize <= entry->callback->maxProgressSize) { + if (processedSize < entry->callback->maxProgressSize) { return; } entry->callback->maxProgressSize = processedSize; @@ -565,7 +572,11 @@ void Copy::ReadNotifyEvent(std::shared_ptr infos) infos->run = false; return; } - OnFileReceive(infos); + auto currentTime = std::chrono::steady_clock::now(); + if (currentTime >= infos->notifyTime_) { + OnFileReceive(infos); + infos->notifyTime_ = currentTime + NOTIFY_PROGRESS_DELAY; + } index += sizeof(struct inotify_event) + event->len; } } @@ -622,7 +633,7 @@ tuple> Copy::CreateFileInfos( infos->listener = listener; infos->srcPath = ConvertUriToPath(infos->srcUri); infos->destPath = ConvertUriToPath(infos->destUri); - + infos->notifyTime_ = std::chrono::steady_clock::now() + NOTIFY_PROGRESS_DELAY; if (listener) { infos->hasListener = true; } diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.h b/interfaces/kits/js/src/mod_fs/properties/copy.h index ebb0403a4..1694ddd7d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.h +++ b/interfaces/kits/js/src/mod_fs/properties/copy.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "bundle_mgr_client_impl.h" #include "common_func.h" @@ -74,6 +75,7 @@ struct FileInfos { std::string destUri; std::string srcPath; std::string destPath; + std::chrono::steady_clock::time_point notifyTime; int32_t notifyFd = -1; int32_t eventFd = -1; bool run = true; -- Gitee From 5992c28efaf00aa592b9ed9dafe70bd88c4beac1 Mon Sep 17 00:00:00 2001 From: h30051954 Date: Fri, 29 Dec 2023 15:10:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: h30051954 --- interfaces/kits/js/src/mod_fs/properties/copy.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 05eaa127e..2b8ee3963 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -573,9 +573,9 @@ void Copy::ReadNotifyEvent(std::shared_ptr infos) return; } auto currentTime = std::chrono::steady_clock::now(); - if (currentTime >= infos->notifyTime_) { + if (currentTime >= infos->notifyTime) { OnFileReceive(infos); - infos->notifyTime_ = currentTime + NOTIFY_PROGRESS_DELAY; + infos->notifyTime = currentTime + NOTIFY_PROGRESS_DELAY; } index += sizeof(struct inotify_event) + event->len; } @@ -633,7 +633,7 @@ tuple> Copy::CreateFileInfos( infos->listener = listener; infos->srcPath = ConvertUriToPath(infos->srcUri); infos->destPath = ConvertUriToPath(infos->destUri); - infos->notifyTime_ = std::chrono::steady_clock::now() + NOTIFY_PROGRESS_DELAY; + infos->notifyTime = std::chrono::steady_clock::now() + NOTIFY_PROGRESS_DELAY; if (listener) { infos->hasListener = true; } -- Gitee