From 25fd9f55ed30f26cb45dc7067ac917cfd1c4266e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=AD=90=E6=81=92?= Date: Wed, 18 Jun 2025 15:11:45 +0800 Subject: [PATCH] add linux errcode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 魏子恒 --- .../kits/js/src/mod_fs/properties/copydir.cpp | 1 + .../kits/js/src/mod_fs/properties/fdatasync.cpp | 2 +- interfaces/kits/js/src/mod_fs/properties/fsync.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/mkdtemp.cpp | 2 +- interfaces/kits/js/src/mod_fs/properties/move.cpp | 5 +++-- .../kits/js/src/mod_fs/properties/movedir.cpp | 4 ++-- .../js/src/mod_fs/properties/prop_n_exporter.cpp | 13 ++++++++----- .../kits/js/src/mod_fs/properties/read_lines.cpp | 2 +- interfaces/kits/js/src/mod_fs/properties/rename.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/symlink.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/truncate.cpp | 3 ++- 11 files changed, 25 insertions(+), 19 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copydir.cpp b/interfaces/kits/js/src/mod_fs/properties/copydir.cpp index 1c643abb8..d71ce9c52 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copydir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copydir.cpp @@ -282,6 +282,7 @@ napi_value CopyDir::Sync(napi_env env, napi_callback_info info) NError(ret).ThrowErrAddData(env, EEXIST, PushErrFilesInData(env, errfiles)); return nullptr; } else if (ret) { + HILOGE("Failed to copy dir, ret %{public}d", ret); NError(ret).ThrowErr(env); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp b/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp index c50b00950..94ace2d8e 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp @@ -86,7 +86,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); + HILOGE("Failed to transfer data associated with file descriptor: %{public}d, ret %{public}d", fd, ret); 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 ceec9a7e5..85c22577c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fsync.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fsync.cpp @@ -51,7 +51,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); + HILOGE("Failed to transfer data associated with file descriptor: %{public}d, ret:%{public}d", fd, ret); NError(ret).ThrowErr(env); return nullptr; } @@ -83,7 +83,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); + HILOGE("Failed to transfer data associated with file descriptor: %{public}d, ret %{public}d", fd, ret); return NError(ret); } else { 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 2d8ab1822..c304e4a67 100755 --- a/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp @@ -69,7 +69,7 @@ static NError MkdTempExec(shared_ptr arg, const 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"); + HILOGE("Failed to create a temporary directory with path ret %{public}d", ret); return NError(ret); } else { *arg = mkdtemp_req->path; diff --git a/interfaces/kits/js/src/mod_fs/properties/move.cpp b/interfaces/kits/js/src/mod_fs/properties/move.cpp index 6898046bc..d6c03bd85 100644 --- a/interfaces/kits/js/src/mod_fs/properties/move.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/move.cpp @@ -143,7 +143,7 @@ static int RenameFile(const string &src, const string &dest) return CopyAndDeleteFile(src, dest); } if (ret < 0) { - HILOGE("Failed to move file using rename syscall."); + HILOGE("Failed to move file using rename syscall, ret:%{public}d", ret); return ret; } return ERRNO_NOERR; @@ -160,7 +160,7 @@ static int MoveFile(const string &src, const string &dest, int mode) return EEXIST; } if (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) { - HILOGE("Failed to access destPath with MODE_THROW_ERR."); + HILOGE("Failed to access destPath with MODE_THROW_ERR, ret:%{public}d", ret); return ret; } } else { @@ -207,6 +207,7 @@ napi_value Move::Async(napi_env env, napi_callback_info info) auto cbExec = [srcPath = string(src.get()), destPath = string(dest.get()), mode = mode]() -> NError { int ret = MoveFile(srcPath, destPath, mode); if (ret) { + HILOGE("Failed movefile ret %{public}d", ret); return NError(ret); } return NError(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 a17abd2d4..31eee911c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -260,7 +260,7 @@ static int MoveDirFunc(const string &src, const string &dest, const int mode, de if (mode == DIRMODE_DIRECTORY_REPLACE) { int removeRes = RmDirectory(destStr); if (removeRes) { - HILOGE("Failed to remove dest directory in DIRMODE_DIRECTORY_REPLACE"); + HILOGE("Failed to remove dest directory in DIRMODE_DIRECTORY_REPLACE, ret %{public}d", removeRes); return removeRes; } } @@ -277,7 +277,7 @@ static int MoveDirFunc(const string &src, const string &dest, const int mode, de } int removeRes = RmDirectory(src); if (removeRes) { - HILOGE("Failed to remove src directory"); + HILOGE("Failed to remove src directory, ret %{public}d", removeRes); return removeRes; } } 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 1191c3311..b1ff25baf 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 @@ -263,7 +263,7 @@ napi_value PropNExporter::AccessSync(napi_env env, napi_callback_info info) bool isAccess = false; int ret = AccessCore(args.path, args.mode, args.flag); if (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) { - HILOGE("Failed to access file by path"); + HILOGE("Failed to access file by path, ret:%{public}d", ret); NError(ret).ThrowErr(env); return nullptr; } @@ -296,6 +296,9 @@ napi_value PropNExporter::Access(napi_env env, napi_callback_info info) } auto cbExec = [path = args.path, result, mode = args.mode, flag = args.flag]() -> NError { int ret = AccessCore(path, mode, flag); + if (ret < 0) { + HILOGE("Accesscore finish ret %{public}d", ret); + } if (ret == 0) { result->isAccess = true; } @@ -343,7 +346,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) { - HILOGD("Failed to unlink with path"); + HILOGD("Failed to unlink with path ret %{public}d", ret); return NError(ret); } return NError(ERRNO_NOERR); @@ -390,7 +393,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) { - HILOGD("Failed to unlink with path"); + HILOGD("Failed to unlink with path ret %{public}d", ret); NError(ret).ThrowErr(env); return nullptr; } @@ -419,7 +422,7 @@ static NError MkdirExec(const string &path, bool recursion, bool hasOption) return NError(EEXIST); } if (ret != -ENOENT) { - HILOGE("Failed to check for illegal path or request for heap memory"); + HILOGE("Failed to check for illegal path or request for heap memory, ret: %{public}d", ret); return NError(ret); } if (::Mkdirs(path.c_str(), static_cast(recursion)) < 0) { @@ -428,7 +431,7 @@ static NError MkdirExec(const string &path, bool recursion, bool hasOption) } ret = AccessCore(path, 0); if (ret) { - HILOGE("Failed to verify the result of Mkdirs function"); + HILOGE("Failed to verify the result of Mkdirs function, ret: %{public}d", ret); return NError(ret); } return NError(ERRNO_NOERR); diff --git a/interfaces/kits/js/src/mod_fs/properties/read_lines.cpp b/interfaces/kits/js/src/mod_fs/properties/read_lines.cpp index dc94ed0fe..2a3142410 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_lines.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_lines.cpp @@ -112,7 +112,7 @@ static NError AsyncExec(ReaderIteratorArg &readerIterator, const string &pathStr } int ret = GetFileSize(pathStr, readerIterator.offset); if (ret < 0) { - HILOGE("Failed to get size of the file"); + HILOGE("Failed to get size of the file ret %{public}d", ret); return NError(ret); } diff --git a/interfaces/kits/js/src/mod_fs/properties/rename.cpp b/interfaces/kits/js/src/mod_fs/properties/rename.cpp index 30aef30f9..c71258c94 100755 --- a/interfaces/kits/js/src/mod_fs/properties/rename.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/rename.cpp @@ -60,7 +60,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"); + HILOGE("Failed to rename file with path ret %{public}d", ret); NError(ret).ThrowErr(env); return nullptr; } @@ -100,7 +100,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"); + HILOGE("Failed to rename file with path ret %{public}d", ret); 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 3ada5d149..a83e8e187 100755 --- a/interfaces/kits/js/src/mod_fs/properties/symlink.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/symlink.cpp @@ -69,7 +69,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"); + HILOGE("Failed to create a link for old path ret %{public}d", ret); NError(ret).ThrowErr(env); return nullptr; } @@ -102,7 +102,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"); + HILOGE("Failed to create a link for old path ret %{public}d", ret); 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 3e2837433..4691f446b 100644 --- a/interfaces/kits/js/src/mod_fs/properties/truncate.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/truncate.cpp @@ -60,6 +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) { + HILOGE("Failed to open by libuv ret %{public}d", ret); return NError(ret); } std::unique_ptr ftruncate_req = { @@ -70,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"); + HILOGE("Failed to truncate file by path ret %{public}d", ret); return NError(ret); } } else { -- Gitee