From 7e53b76b48acaa354ed5ff230a1d4f0fbe126f53 Mon Sep 17 00:00:00 2001 From: h30051954 Date: Wed, 7 Feb 2024 18:22:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=B8=A6=E5=90=8E=E7=BC=80=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=A0=A1=E9=AA=8C=E5=9C=BA=E6=99=AF=E6=B7=BB=E5=8A=A0?= 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 | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index badbd50c2..20ce244b5 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -344,10 +344,33 @@ int Copy::CopyDirFunc(const string &src, const string &dest, std::shared_ptr infos, std::shared_ptr callback) { - if (infos->destPath.find(infos->srcPath) != std::string::npos) { - HILOGE("The src directory is the subdirectory of dest"); + if (!infos->srcPath.empty() && !infos->destPath.empty()) { + if (fs::exists(infos->srcPath)) { + HILOGE("The src directory is not exist"); + return ENOENT; + } + } else { + HILOGE("The path is empty"); return EINVAL; } + if (IsFile(infos->srcPath)) { + if (infos->srcPath == infos->destPath) { + HILOGE("The src directory is the subdirectory of dest ,path = %{public}s", infos->srcPath.c_str()); + return EINVAL; + } + CheckOrCreatePath(infos->destPath); + } else { + if (infos->srcPath.back() != '/') { + infos->srcPath += '/'; + } else if (infos->destPath.back() != '/') { + infos->destPath += '/'; + } + if (infos->destPath.find(infos->srcPath) != std::string::npos) { + HILOGE("The src directory is the subdirectory of dest, srcPath = %{public}s, destPath = %{public}s", + infos->srcPath.c_str(), infos->destPath.c_str()); + return EINVAL; + } + } if (IsFile(infos->srcPath)) { CheckOrCreatePath(infos->destPath); } -- Gitee