diff --git a/interfaces/kits/js/src/mod_fs/properties/copydir.cpp b/interfaces/kits/js/src/mod_fs/properties/copydir.cpp index 16329aff9e099dc82c28e3f8ef6ccbb02231d277..6682b02dea213673f8e06d61dd8b3c6592a01b38 100755 --- a/interfaces/kits/js/src/mod_fs/properties/copydir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copydir.cpp @@ -108,18 +108,13 @@ static int CopyFile(const string &src, const string &dest) HILOGE("Failed to copy file due to existing destPath with throw err"); return EEXIST; } - std::unique_ptr copyfile_req = { - new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; - if (copyfile_req == nullptr) { - HILOGE("Failed to request heap memory."); - return ENOMEM; - } - - int ret = uv_fs_copyfile(nullptr, copyfile_req.get(), src.c_str(), dest.c_str(), - UV_FS_COPYFILE_EXCL, nullptr); - if (ret < 0) { - HILOGE("Failed to move file using copyfile interface"); - return -ret; + filesystem::path srcPath(src); + filesystem::path dstPath(dest); + std::error_code errCode; + auto copyFileRes = filesystem::copy_file(srcPath, dstPath, filesystem::copy_options::overwrite_existing, errCode); + if (!copyFileRes) { + HILOGE("Failed to copy file, error code: %{public}d", errCode.value()); + return errCode.value(); } return ERRNO_NOERR; } diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index 195aa0e29c077052453804217970645d1b27f0c6..d20384cfc9e1323d4d8842527655e8f10a9eac92 100755 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -86,13 +86,14 @@ static tuple, unique_ptr, int> ParseJsOperand(n static int CopyAndDeleteFile(const string &src, const string &dest) { - uv_fs_t copyfile_req; - int ret = uv_fs_copyfile(nullptr, ©file_req, src.c_str(), dest.c_str(), UV_FS_COPYFILE_FICLONE_FORCE, nullptr); - if (ret < 0) { - HILOGE("Failed to move file using copyfile interface"); - return -ret; + filesystem::path srcPath(src); + filesystem::path dstPath(dest); + std::error_code errCode; + auto copyFileRes = filesystem::copy_file(srcPath, dstPath, filesystem::copy_options::overwrite_existing, errCode); + if (!copyFileRes) { + HILOGE("Failed to copy file, error code: %{public}d", errCode.value()); + return errCode.value(); } - uv_fs_req_cleanup(©file_req); uv_fs_t unlink_req; int unlinkSrcRes = uv_fs_unlink(nullptr, &unlink_req, src.c_str(), nullptr); if (unlinkSrcRes < 0) {