From b858c449dd1783c094f0060e6d55e62d821b048b Mon Sep 17 00:00:00 2001 From: h30051954 Date: Fri, 2 Feb 2024 18:54:55 +0800 Subject: [PATCH] =?UTF-8?q?copy=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 | 15 ++++++++++++--- interfaces/kits/js/src/mod_fs/properties/copy.h | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 678dda4b9..283888ed3 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -249,6 +249,13 @@ static void Deleter(struct NameList *arg) free(arg->namelist); } +void Copy::GetRealPath(string &path) +{ + unique_ptr absPath = make_unique(PATH_MAX + 1); + realpath(path.c_str(),absPath.get()); + path = absPath.get(); +} + uint64_t Copy::GetDirSize(std::shared_ptr infos, std::string path) { unique_ptr pNameList = { new (nothrow) struct NameList, Deleter }; @@ -322,8 +329,8 @@ int Copy::CopyDirFunc(const string &src, const string &dest, std::shared_ptr infos, std::shared_ptr callback) { - if (infos->srcPath == infos->destPath) { - HILOGE("The src and dest are the same."); + if (infos->destPath.find(infos->srcPath) != std::string::npos) { + HILOGE("The src directory is the subdirectory of dest"); return EINVAL; } if (IsFile(infos->srcPath)) { @@ -671,6 +678,8 @@ tuple> Copy::CreateFileInfos( infos->listener = listener; infos->srcPath = ConvertUriToPath(infos->srcUri); infos->destPath = ConvertUriToPath(infos->destUri); + GetRealPath(infos->destPath); + GetRealPath(infos->srcPath); 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 dc792fa96..22e55f87e 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.h +++ b/interfaces/kits/js/src/mod_fs/properties/copy.h @@ -93,7 +93,7 @@ struct FileInfos { if (srcUri == infos.srcUri) { return destUri < infos.destUri; } - return (srcUri < infos.srcUri || destUri < infos.destUri); + return srcUri < infos.srcUri; } }; @@ -165,6 +165,7 @@ private: static bool IsDirectory(const std::string &path); static bool IsFile(const std::string &path); static std::string ConvertUriToPath(const std::string &uri); + static void GetRealPath(string &path); }; } // namespace ModuleFileIO } // namespace FileManagement -- Gitee