From 6096adcbd85a1d94dc8cd47c1dd35a2df49a3fd8 Mon Sep 17 00:00:00 2001 From: wangluyao Date: Thu, 12 Sep 2024 20:12:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80tdd=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangluyao --- .../kits/js/src/mod_fs/properties/copy.cpp | 36 +++++-------------- .../kits/js/src/mod_fs/properties/copy.h | 4 +-- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index bc584695a..c91208e15 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -188,26 +188,22 @@ bool Copy::IsRemoteUri(const std::string &uri) return uri.find(NETWORK_PARA) != uri.npos; } -bool Copy::IsDirectory(const std::string &path, int &errCode) +bool Copy::IsDirectory(const std::string &path) { - errCode = 0; struct stat buf {}; int ret = stat(path.c_str(), &buf); if (ret == -1) { - errCode = errno; HILOGE("stat failed, errno is %{public}d", errno); return false; } return (buf.st_mode & S_IFMT) == S_IFDIR; } -bool Copy::IsFile(const std::string &path, int &errCode) +bool Copy::IsFile(const std::string &path) { - errCode = 0; struct stat buf {}; int ret = stat(path.c_str(), &buf); if (ret == -1) { - errCode = errno; HILOGI("stat failed, errno is %{public}d, ", errno); return false; } @@ -431,19 +427,11 @@ int Copy::CopyDirFunc(const string &src, const string &dest, std::shared_ptr infos, std::shared_ptr callback) { - int errCode = 0; - infos->isFile = IsMediaUri(infos->srcUri) || IsFile(infos->srcPath, errCode); - if (errCode != 0) { - return errCode; - } - if (!infos->isFile && !IsDirectory(infos->srcPath, errCode)) { - return EINVAL; - } - if (infos->srcPath == infos->destPath) { - HILOGE("The src and dest is same, path = %{public}s", infos->srcPath.c_str()); - return EINVAL; - } if (infos->isFile) { + if (infos->srcPath == infos->destPath) { + HILOGE("The src and dest is same"); + return EINVAL; + } CheckOrCreatePath(infos->destPath); } if (!infos->hasListener) { @@ -796,6 +784,7 @@ tuple> Copy::CreateFileInfos( infos->destPath = dstFileUri.GetPath(); infos->srcPath = GetRealPath(infos->srcPath); infos->destPath = GetRealPath(infos->destPath); + infos->isFile = IsMediaUri(infos->srcUri) || IsFile(infos->srcPath); infos->notifyTime = std::chrono::steady_clock::now() + NOTIFY_PROGRESS_DELAY; if (listener) { infos->hasListener = true; @@ -820,15 +809,11 @@ void Copy::StartNotify(std::shared_ptr infos, std::shared_ptr infos) { - int errCode = 0; - if (infos->isFile && IsFile(infos->destPath, errCode) && errCode == 0) { + if (infos->isFile && IsFile(infos->destPath)) { // copyFile return CopyFile(infos->srcPath.c_str(), infos->destPath.c_str(), infos); } - if (errCode != 0) { - return errCode; - } - if (!infos->isFile && IsDirectory(infos->destPath, errCode) && errCode == 0) { + if (!infos->isFile && IsDirectory(infos->destPath)) { if (infos->srcPath.back() != '/') { infos->srcPath += '/'; } @@ -838,9 +823,6 @@ int Copy::ExecCopy(std::shared_ptr infos) // copyDir return CopyDirFunc(infos->srcPath.c_str(), infos->destPath.c_str(), infos); } - if (errCode != 0) { - return errCode; - } 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 52d2fc400..80dac1048 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.h +++ b/interfaces/kits/js/src/mod_fs/properties/copy.h @@ -172,8 +172,8 @@ private: // operator of uri or path static bool IsValidUri(const std::string &uri); static bool IsRemoteUri(const std::string &uri); - static bool IsDirectory(const std::string &path, int &errCode); - static bool IsFile(const std::string &path, int &errCode); + static bool IsDirectory(const std::string &path); + static bool IsFile(const std::string &path); static bool IsMediaUri(const std::string &uriPath); static std::string ConvertUriToPath(const std::string &uri); static std::string GetRealPath(const std::string& path); -- Gitee