From a2db70540117515e0e7174642f6bee302ae8dacf Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Thu, 8 Jun 2023 16:49:10 +0800 Subject: [PATCH 1/3] fs_rmdir_libuv Signed-off-by: 18721213663 --- .../kits/js/src/mod_fs/properties/close.cpp | 2 +- .../js/src/mod_fs/properties/fdatasync.cpp | 4 +- .../kits/js/src/mod_fs/properties/fsync.cpp | 4 +- .../kits/js/src/mod_fs/properties/lstat.cpp | 4 +- .../kits/js/src/mod_fs/properties/mkdtemp.cpp | 4 +- .../kits/js/src/mod_fs/properties/move.cpp | 12 ++--- .../kits/js/src/mod_fs/properties/movedir.cpp | 4 +- .../kits/js/src/mod_fs/properties/open.cpp | 4 +- .../src/mod_fs/properties/prop_n_exporter.cpp | 22 +++++----- .../kits/js/src/mod_fs/properties/rename.cpp | 4 +- .../kits/js/src/mod_fs/properties/stat.cpp | 4 +- .../kits/js/src/mod_fs/properties/symlink.cpp | 4 +- .../js/src/mod_fs/properties/truncate.cpp | 4 +- utils/filemgmt_libn/include/n_error.h | 44 +++++++++++++++++++ utils/filemgmt_libn/src/n_error.cpp | 24 +++++++--- 15 files changed, 101 insertions(+), 43 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/close.cpp b/interfaces/kits/js/src/mod_fs/properties/close.cpp index 76b639afe..0080d78c9 100755 --- a/interfaces/kits/js/src/mod_fs/properties/close.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close.cpp @@ -53,7 +53,7 @@ static NError CloseFd(int fd) int ret = uv_fs_close(nullptr, close_req.get(), fd, nullptr); if (ret < 0) { HILOGE("Failed to close file with ret: %{public}d", ret); - return NError(errno); + return NError(ret); } return NError(ERRNO_NOERR); } diff --git a/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp b/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp index 6c683170c..c50b00950 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp @@ -54,7 +54,7 @@ napi_value Fdatasync::Sync(napi_env env, napi_callback_info info) int ret = uv_fs_fdatasync(nullptr, fdatasync_req.get(), fd, nullptr); if (ret < 0) { HILOGE("Failed to transfer data associated with file descriptor: %{public}d, ret:%{public}d", fd, ret); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } @@ -87,7 +87,7 @@ napi_value Fdatasync::Async(napi_env env, napi_callback_info info) int ret = uv_fs_fdatasync(nullptr, fdatasync_req.get(), fd, nullptr); if (ret < 0) { HILOGE("Failed to transfer data associated with file descriptor: %{public}d", fd); - return NError(errno); + return NError(ret); } else { return NError(ERRNO_NOERR); } diff --git a/interfaces/kits/js/src/mod_fs/properties/fsync.cpp b/interfaces/kits/js/src/mod_fs/properties/fsync.cpp index b252665c7..ceec9a7e5 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fsync.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fsync.cpp @@ -52,7 +52,7 @@ napi_value Fsync::Sync(napi_env env, napi_callback_info info) int ret = uv_fs_fsync(nullptr, fsync_req.get(), fd, nullptr); if (ret < 0) { HILOGE("Failed to transfer data associated with file descriptor: %{public}d", fd); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } return NVal::CreateUndefined(env).val_; @@ -84,7 +84,7 @@ napi_value Fsync::Async(napi_env env, napi_callback_info info) int ret = uv_fs_fsync(nullptr, fsync_req.get(), fd, nullptr); if (ret < 0) { HILOGE("Failed to transfer data associated with file descriptor: %{public}d", fd); - return NError(errno); + return NError(ret); } else { return NError(ERRNO_NOERR); } diff --git a/interfaces/kits/js/src/mod_fs/properties/lstat.cpp b/interfaces/kits/js/src/mod_fs/properties/lstat.cpp index 407b59515..823e9603c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/lstat.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/lstat.cpp @@ -53,7 +53,7 @@ napi_value Lstat::Sync(napi_env env, napi_callback_info info) int ret = uv_fs_lstat(nullptr, lstat_req.get(), pathPtr.get(), nullptr); if (ret < 0) { HILOGE("Failed to get stat of file by path %{public}s", pathPtr.get()); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } @@ -72,7 +72,7 @@ static NError LstatExec(shared_ptr arg, string path) int ret = uv_fs_lstat(nullptr, lstat_req.get(), path.c_str(), nullptr); if (ret < 0) { HILOGE("Failed to get stat of file by path: %{public}s, ret: %{public}d", path.c_str(), ret); - return NError(errno); + return NError(ret); } else { arg->stat_ = lstat_req->statbuf; return NError(ERRNO_NOERR); diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp b/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp index 13c22b6d4..541fdb6a5 100755 --- a/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp @@ -52,7 +52,7 @@ napi_value Mkdtemp::Sync(napi_env env, napi_callback_info info) int ret = uv_fs_mkdtemp(nullptr, mkdtemp_req.get(), const_cast(path.c_str()), nullptr); if (ret < 0) { HILOGE("Failed to create a temporary directory with path"); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } @@ -70,7 +70,7 @@ static NError MkdTempExec(shared_ptr arg, string path) int ret = uv_fs_mkdtemp(nullptr, mkdtemp_req.get(), path.c_str(), nullptr); if (ret < 0) { HILOGE("Failed to create a temporary directory with path"); - return NError(errno); + return NError(ret); } else { *arg = mkdtemp_req->path; return NError(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 5592b6868..a27edca34 100644 --- a/interfaces/kits/js/src/mod_fs/properties/move.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/move.cpp @@ -89,7 +89,7 @@ static int CopyAndDeleteFile(const string &src, const string &dest) uv_fs_req_cleanup(©file_req); if (ret < 0) { HILOGE("Failed to move file using copyfile interface."); - return errno; + return ret; } uv_fs_t unlink_req; ret = uv_fs_unlink(nullptr, &unlink_req, src.c_str(), nullptr); @@ -100,7 +100,7 @@ static int CopyAndDeleteFile(const string &src, const string &dest) HILOGE("Failed to unlink dest file"); } uv_fs_req_cleanup(&unlink_req); - return errno; + return ret; } uv_fs_req_cleanup(&unlink_req); return ERRNO_NOERR; @@ -111,12 +111,12 @@ static int RenameFile(const string &src, const string &dest) int ret = 0; uv_fs_t rename_req; ret = uv_fs_rename(nullptr, &rename_req, src.c_str(), dest.c_str(), nullptr); - if (ret < 0 && errno == EXDEV) { + if (ret < 0 && (string_view(uv_err_name(ret)) != "EXDEV")) { return CopyAndDeleteFile(src, dest); } if (ret < 0) { HILOGE("Failed to move file using rename syscall."); - return errno; + return ret; } return ERRNO_NOERR; } @@ -131,9 +131,9 @@ static int MoveFile(const string &src, const string &dest, int mode) HILOGE("Failed to move file due to existing destPath with MODE_THROW_ERR."); return EEXIST; } - if (ret < 0 && errno != ENOENT) { + if (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) { HILOGE("Failed to access destPath with MODE_THROW_ERR."); - return errno; + return ret; } } return RenameFile(src, dest); diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index aeb71a8d9..26137f35a 100755 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -120,7 +120,7 @@ static int RenameFile(const string &src, const string &dest, const int mode) uv_fs_t rename_req; int res = uv_fs_rename(nullptr, &rename_req, src.c_str(), dest.c_str(), nullptr); uv_fs_req_cleanup(&rename_req); - if (res < 0 && errno == EXDEV) { + if (res < 0 && (string_view(uv_err_name(res)) != "EXDEV")) { HILOGE("Failed to rename file due to EXDEV"); return CopyAndDeleteFile(src, dest); } @@ -144,7 +144,7 @@ static int RenameDir(const string &src, const string &dest, const int mode, vect uv_fs_t rename_req; int ret = uv_fs_rename(nullptr, &rename_req, src.c_str(), dest.c_str(), nullptr); uv_fs_req_cleanup(&rename_req); - if (ret < 0 && errno == EXDEV) { + if (ret < 0 && (string_view(uv_err_name(ret)) != "EXDEV")) { HILOGE("Failed to rename file due to EXDEV"); return RecurMoveDir(src, dest, mode, errfiles); } diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index ea5f82bc1..0e2b7413f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -239,7 +239,7 @@ napi_value Open::Sync(napi_env env, napi_callback_info info) S_IWUSR | S_IRGRP | S_IWGRP, nullptr); if (ret < 0) { HILOGE("Failed to open file for libuv error %{public}d", ret); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } auto file = InstantiateFile(env, ret, pathStr, false).val_; @@ -313,7 +313,7 @@ napi_value Open::Async(napi_env env, napi_callback_info info) S_IWUSR | S_IRGRP | S_IWGRP, nullptr); if (ret < 0) { HILOGE("Failed to open file for libuv error %{public}d", ret); - return NError(errno); + return NError(ret); } arg->fd = ret; arg->path = pathStr; diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index b7573c89e..0ba33786f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -81,9 +81,9 @@ napi_value PropNExporter::AccessSync(napi_env env, napi_callback_info info) return nullptr; } int ret = uv_fs_access(nullptr, access_req.get(), path.get(), 0, nullptr); - if (ret < 0 && errno != ENOENT) { + if (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) { HILOGE("Failed to access file by path"); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } if (ret == 0) { @@ -125,7 +125,7 @@ napi_value PropNExporter::Access(napi_env env, napi_callback_info info) if (ret == 0) { result->isAccess = true; } - return (ret < 0 && errno != ENOENT) ? NError(errno) : NError(ERRNO_NOERR); + return (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) ? NError(ret) : NError(ERRNO_NOERR); }; auto cbComplete = [result](napi_env env, NError err) -> NVal { @@ -170,7 +170,7 @@ napi_value PropNExporter::Unlink(napi_env env, napi_callback_info info) int ret = uv_fs_unlink(nullptr, unlink_req.get(), path.c_str(), nullptr); if (ret < 0) { HILOGE("Failed to unlink with path"); - return NError(errno); + return NError(ret); } return NError(ERRNO_NOERR); }; @@ -217,7 +217,7 @@ napi_value PropNExporter::UnlinkSync(napi_env env, napi_callback_info info) int ret = uv_fs_unlink(nullptr, unlink_req.get(), path.get(), nullptr); if (ret < 0) { HILOGE("Failed to unlink with path"); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } @@ -250,7 +250,7 @@ napi_value PropNExporter::Mkdir(napi_env env, napi_callback_info info) int ret = uv_fs_mkdir(nullptr, mkdir_req.get(), path.c_str(), DIR_DEFAULT_PERM, nullptr); if (ret < 0) { HILOGE("Failed to create directory"); - return NError(errno); + return NError(ret); } return NError(ERRNO_NOERR); }; @@ -297,7 +297,7 @@ napi_value PropNExporter::MkdirSync(napi_env env, napi_callback_info info) int ret = uv_fs_mkdir(nullptr, mkdir_req.get(), path.get(), DIR_DEFAULT_PERM, nullptr); if (ret < 0) { HILOGE("Failed to create directory"); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } @@ -345,7 +345,7 @@ napi_value PropNExporter::ReadSync(napi_env env, napi_callback_info info) int ret = uv_fs_read(nullptr, read_req.get(), fd, &buffer, 1, offset, nullptr); if (ret < 0) { HILOGE("Failed to read file for %{public}d", ret); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } @@ -364,7 +364,7 @@ static NError ReadExec(shared_ptr arg, char *buf, size_t len, in int ret = uv_fs_read(nullptr, read_req.get(), fd, &buffer, 1, offset, nullptr); if (ret < 0) { HILOGE("Failed to read file for %{public}d", ret); - return NError(errno); + return NError(ret); } arg->lenRead = ret; return NError(ERRNO_NOERR); @@ -439,7 +439,7 @@ static NError WriteExec(shared_ptr arg, char *buf, size_t len, int ret = uv_fs_write(nullptr, write_req.get(), fd, &buffer, 1, offset, nullptr); if (ret < 0) { HILOGE("Failed to write file for %{public}d", ret); - return NError(errno); + return NError(ret); } arg->actLen = ret; return NError(ERRNO_NOERR); @@ -544,7 +544,7 @@ napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info) int ret = uv_fs_write(nullptr, write_req.get(), fd, &buffer, 1, offset, nullptr); if (ret < 0) { HILOGE("Failed to write file for %{public}d", ret); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/properties/rename.cpp b/interfaces/kits/js/src/mod_fs/properties/rename.cpp index dd05e02f8..7a5f6b919 100755 --- a/interfaces/kits/js/src/mod_fs/properties/rename.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/rename.cpp @@ -61,7 +61,7 @@ napi_value Rename::Sync(napi_env env, napi_callback_info info) int ret = uv_fs_rename(nullptr, rename_req.get(), src.get(), dest.get(), nullptr); if (ret < 0) { HILOGE("Failed to rename file with path"); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } @@ -101,7 +101,7 @@ napi_value Rename::Async(napi_env env, napi_callback_info info) int ret = uv_fs_rename(nullptr, rename_req.get(), opath.c_str(), npath.c_str(), nullptr); if (ret < 0) { HILOGE("Failed to rename file with path"); - return NError(errno); + return NError(ret); } return NError(ERRNO_NOERR); }; diff --git a/interfaces/kits/js/src/mod_fs/properties/stat.cpp b/interfaces/kits/js/src/mod_fs/properties/stat.cpp index 2d60b89c2..490d79d36 100644 --- a/interfaces/kits/js/src/mod_fs/properties/stat.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/stat.cpp @@ -59,13 +59,13 @@ static NError CheckFsStat(const FileInfo &fileInfo, uv_fs_t* req) int ret = uv_fs_stat(nullptr, req, fileInfo.path.get(), nullptr); if (ret < 0) { HILOGE("Failed to stat file with path"); - return NError(errno); + return NError(ret); } } else { int ret = uv_fs_fstat(nullptr, req, fileInfo.fdg->GetFD(), nullptr); if (ret < 0) { HILOGE("Failed to stat file with fd"); - return NError(errno); + return NError(ret); } } return NError(ERRNO_NOERR); diff --git a/interfaces/kits/js/src/mod_fs/properties/symlink.cpp b/interfaces/kits/js/src/mod_fs/properties/symlink.cpp index 62881ee16..176a19ddd 100755 --- a/interfaces/kits/js/src/mod_fs/properties/symlink.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/symlink.cpp @@ -70,7 +70,7 @@ napi_value Symlink::Sync(napi_env env, napi_callback_info info) int ret = uv_fs_symlink(nullptr, symlink_req.get(), oldPath.c_str(), newPath.c_str(), 0, nullptr); if (ret < 0) { HILOGE("Failed to create a link for old path"); - NError(errno).ThrowErr(env); + NError(ret).ThrowErr(env); return nullptr; } @@ -103,7 +103,7 @@ napi_value Symlink::Async(napi_env env, napi_callback_info info) int ret = uv_fs_symlink(nullptr, symlink_req.get(), oldPath.c_str(), newPath.c_str(), 0, nullptr); if (ret < 0) { HILOGE("Failed to create a link for old path"); - return NError(errno); + return NError(ret); } return NError(ERRNO_NOERR); }; diff --git a/interfaces/kits/js/src/mod_fs/properties/truncate.cpp b/interfaces/kits/js/src/mod_fs/properties/truncate.cpp index 695b6a45c..a793c2811 100644 --- a/interfaces/kits/js/src/mod_fs/properties/truncate.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/truncate.cpp @@ -60,7 +60,7 @@ static NError TruncateCore(napi_env env, FileInfo &fileInfo, int64_t truncateLen int ret = uv_fs_open(nullptr, open_req.get(), fileInfo.path.get(), O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, nullptr); if (ret < 0) { - return NError(errno); + return NError(ret); } std::unique_ptr ftruncate_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; @@ -71,7 +71,7 @@ static NError TruncateCore(napi_env env, FileInfo &fileInfo, int64_t truncateLen ret = uv_fs_ftruncate(nullptr, ftruncate_req.get(), ret, truncateLen, nullptr); if (ret < 0) { HILOGE("Failed to truncate file by path"); - return NError(errno); + return NError(ret); } } else { std::unique_ptr ftruncate_req = { diff --git a/utils/filemgmt_libn/include/n_error.h b/utils/filemgmt_libn/include/n_error.h index b349144cc..1f5debc38 100644 --- a/utils/filemgmt_libn/include/n_error.h +++ b/utils/filemgmt_libn/include/n_error.h @@ -143,6 +143,50 @@ enum CommonErrCode { E_OSNOTSUPPORT = 901 }; +static const std::unordered_map uvCode2ErrCodeTable { + { "EPERM", EPERM }, + { "ENOENT", ENOENT }, + { "ESRCH", ESRCH }, + { "EINTR", EINTR }, + { "EIO", EIO }, + { "ENXIO", ENXIO }, + { "E2BIG", E2BIG }, + { "EBADF", EBADF }, + { "ECHILD", ECHILD }, + { "EAGAIN", EAGAIN }, + { "ENOMEM", ENOMEM }, + { "EACCES", EACCES }, + { "EFAULT", EFAULT }, + { "EBUSY", EBUSY }, + { "EEXIST", EEXIST }, + { "EXDEV", EXDEV }, + { "ENODEV", ENODEV }, + { "ENOTDIR", ENOTDIR }, + { "EISDIR", EISDIR }, + { "EINVAL", EINVAL }, + { "ENFILE", ENFILE }, + { "EMFILE", EMFILE }, + { "ETXTBSY", ETXTBSY }, + { "EFBIG", EFBIG }, + { "ENOSPC", ENOSPC }, + { "ESPIPE", ESPIPE }, + { "EROFS", EROFS }, + { "EMLINK", EMLINK }, + { "EDEADLK", EDEADLK }, + { "ENAMETOOLONG", ENAMETOOLONG }, + { "ENOSYS", ENOSYS }, + { "ENOTEMPTY", ENOTEMPTY }, + { "ELOOP", ELOOP }, + { "EWOULDBLOCK", EWOULDBLOCK }, + { "EBADR", EBADR }, + { "ENOSTR", ENOSTR }, + { "ENODATA", ENODATA }, + { "EOVERFLOW", EOVERFLOW }, + { "EBADFD", EBADFD }, + { "ERESTART", ERESTART }, + { "EDQUOT", EDQUOT }, +}; + static inline std::unordered_map> errCodeTable { { ERRNO_NOERR, { ERRNO_NOERR, "No error imformation" } }, { EPERM, { FILEIO_SYS_CAP_TAG + E_PERM, "Operation not permitted" } }, diff --git a/utils/filemgmt_libn/src/n_error.cpp b/utils/filemgmt_libn/src/n_error.cpp index 8e009481c..9ab361bdc 100644 --- a/utils/filemgmt_libn/src/n_error.cpp +++ b/utils/filemgmt_libn/src/n_error.cpp @@ -19,6 +19,7 @@ #include "filemgmt_libhilog.h" #include "n_val.h" +#include "uv.h" namespace OHOS { namespace FileManagement { @@ -46,16 +47,29 @@ static napi_value GenerateBusinessError(napi_env env, int32_t errCode, string er return businessError; } +static int ConvertUVCode2ErrCode(int errCode) +{ + if (errCode >= 0) { + return errCode; + } + auto uvCode = string_view(uv_err_name(errCode)); + if (uvCode2ErrCodeTable.find(uvCode) != uvCode2ErrCodeTable.end()) { + return uvCode2ErrCodeTable.at(uvCode); + } + return UNKROWN_ERR; +} + NError::NError() {} NError::NError(int errCode) { - if (errCodeTable.find(errCode) != errCodeTable.end()) { - errno_ = errCodeTable.at(errCode).first; - errMsg_ = errCodeTable.at(errCode).second; + int genericCode = ConvertUVCode2ErrCode(errCode); + if (errCodeTable.find(genericCode) != errCodeTable.end()) { + errno_ = errCodeTable.at(genericCode).first; + errMsg_ = errCodeTable.at(genericCode).second; } else { - errno_ = errCode; - errMsg_ = "Unknown error"; + errno_ = errCodeTable.at(UNKROWN_ERR).first; + errMsg_ = errCodeTable.at(UNKROWN_ERR).second; } } -- Gitee From 73120fd69a6eec070ab4efb8687c340c5ac1f9a9 Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Thu, 8 Jun 2023 20:17:35 +0800 Subject: [PATCH 2/3] fs_add_uvcode Signed-off-by: 18721213663 --- interfaces/kits/js/src/mod_fs/properties/movedir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index 26137f35a..da0aa7f67 100755 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -120,7 +120,7 @@ static int RenameFile(const string &src, const string &dest, const int mode) uv_fs_t rename_req; int res = uv_fs_rename(nullptr, &rename_req, src.c_str(), dest.c_str(), nullptr); uv_fs_req_cleanup(&rename_req); - if (res < 0 && (string_view(uv_err_name(res)) != "EXDEV")) { + if (res < 0 && (string_view(uv_err_name(res)) == "EXDEV")) { HILOGE("Failed to rename file due to EXDEV"); return CopyAndDeleteFile(src, dest); } -- Gitee From fbbe1b357d4929ef16119bd74cf2b1a09593c84b Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Thu, 8 Jun 2023 21:13:11 +0800 Subject: [PATCH 3/3] fs_add_uvcode Signed-off-by: 18721213663 --- interfaces/kits/js/src/mod_fs/properties/movedir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index da0aa7f67..195aa0e29 100755 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -144,7 +144,7 @@ static int RenameDir(const string &src, const string &dest, const int mode, vect uv_fs_t rename_req; int ret = uv_fs_rename(nullptr, &rename_req, src.c_str(), dest.c_str(), nullptr); uv_fs_req_cleanup(&rename_req); - if (ret < 0 && (string_view(uv_err_name(ret)) != "EXDEV")) { + if (ret < 0 && (string_view(uv_err_name(ret)) == "EXDEV")) { HILOGE("Failed to rename file due to EXDEV"); return RecurMoveDir(src, dest, mode, errfiles); } -- Gitee