diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp index 6dc697584af071e1cbe1adf4bdea9966c313f3af..92c2455aed6a8a08e28fdc78656a4edc0b903ff8 100755 --- a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -34,6 +35,16 @@ using namespace OHOS::FileManagement::LibN; static NError IsAllPath(FileInfo& srcFile, FileInfo& destFile) { +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + filesystem::path srcPath(string(srcFile.path.get())); + filesystem::path dstPath(string(destFile.path.get())); + 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 NError(errCode.value()); + } +#else std::unique_ptr copyfile_req = { new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!copyfile_req) { @@ -44,8 +55,9 @@ static NError IsAllPath(FileInfo& srcFile, FileInfo& destFile) UV_FS_COPYFILE_FICLONE, nullptr); if (ret < 0) { HILOGE("Failed to copy file when all parameters are paths"); - return NError(errno); + return NError(ret); } +#endif return NError(ERRNO_NOERR); } diff --git a/interfaces/kits/js/src/mod_fs/properties/copydir.cpp b/interfaces/kits/js/src/mod_fs/properties/copydir.cpp index 16329aff9e099dc82c28e3f8ef6ccbb02231d277..033342b01b8d01d38d324c7613a9dde2b1cee824 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); + 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/move.cpp b/interfaces/kits/js/src/mod_fs/properties/move.cpp index e66fab2a7e5b1b52f7359b660ff12809395cdf96..4d0bcdcd6a60d7881455025d8a38c70cfd5e7b91 100644 --- a/interfaces/kits/js/src/mod_fs/properties/move.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/move.cpp @@ -84,6 +84,16 @@ static tuple, unique_ptr, int> ParseJsOperand(n static int CopyAndDeleteFile(const string &src, const string &dest) { int ret = 0; +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + filesystem::path srcPath(src); + filesystem::path dstPath(dest); + 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(); + } +#else uv_fs_t copyfile_req; ret = uv_fs_copyfile(nullptr, ©file_req, src.c_str(), dest.c_str(), MODE_FORCE_MOVE, nullptr); uv_fs_req_cleanup(©file_req); @@ -91,6 +101,7 @@ static int CopyAndDeleteFile(const string &src, const string &dest) HILOGE("Failed to move file using copyfile interface."); return ret; } +#endif uv_fs_t unlink_req; ret = uv_fs_unlink(nullptr, &unlink_req, src.c_str(), nullptr); if (ret < 0) { diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index 195aa0e29c077052453804217970645d1b27f0c6..ac171335cf33176e9a6dc15cd2e0b1821edbf9b5 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); + 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) {