diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index bc584695a84cb422d15e76f251c3c9a510ab35bc..c91208e1515085441f6eb359ba2c0a215dc14b71 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 52d2fc40046f4a9958100bff2886670985ff399a..80dac1048faef0262bbb76099fcffedb05b4c276 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);