From 5fd9f12428999f210c62eb6b393feeb8db01c575 Mon Sep 17 00:00:00 2001 From: gwx1278443 Date: Tue, 19 Mar 2024 16:12:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gwx1278443 --- interfaces/kits/c/environment/environment.c | 6 +++--- interfaces/kits/c/environment/environment.h | 6 +++--- interfaces/kits/c/fileio/fileio.c | 2 +- interfaces/kits/c/fileio/fileio.h | 2 +- .../environment_n_exporter.cpp | 4 ++-- .../src/mod_fileio/properties/copy_file.cpp | 6 +++--- .../src/mod_fileio/properties/ftruncate.cpp | 7 +++---- .../mod_fs/class_watcher/watcher_entity.cpp | 6 +++--- .../class_watcher/watcher_n_exporter.cpp | 6 ++++++ .../kits/js/src/mod_fs/properties/copy.cpp | 20 ++++++++++--------- .../copy_listener/trans_listener.cpp | 2 +- .../src/n_async/n_async_work_callback.cpp | 3 ++- 12 files changed, 39 insertions(+), 31 deletions(-) diff --git a/interfaces/kits/c/environment/environment.c b/interfaces/kits/c/environment/environment.c index b5d45da05..e43bf6a87 100644 --- a/interfaces/kits/c/environment/environment.c +++ b/interfaces/kits/c/environment/environment.c @@ -20,7 +20,7 @@ #include "environment_native.h" #include "../common/error_code.h" -int OH_Environment_GetUserDownloadDir(char **result) +int OhEnvironmentGetUserDownloadDir(char **result) { if (result == NULL) { return GetErrorCode(-PARAMETER_ERROR); @@ -32,7 +32,7 @@ int OH_Environment_GetUserDownloadDir(char **result) return ret; } -int OH_Environment_GetUserDocumentDir(char **result) +int OhEnvironmentGetUserDocumentDir(char **result) { if (result == NULL) { return GetErrorCode(-PARAMETER_ERROR); @@ -44,7 +44,7 @@ int OH_Environment_GetUserDocumentDir(char **result) return ret; } -int OH_Environment_GetUserDesktopDir(char **result) +int OhEnvironmentGetUserDesktopDir(char **result) { if (result == NULL) { return GetErrorCode(-PARAMETER_ERROR); diff --git a/interfaces/kits/c/environment/environment.h b/interfaces/kits/c/environment/environment.h index c0571a7cd..61f29d86c 100644 --- a/interfaces/kits/c/environment/environment.h +++ b/interfaces/kits/c/environment/environment.h @@ -22,9 +22,9 @@ #ifdef __cplusplus extern "C" { #endif /* End of #ifdef __cplusplus */ -int OH_Environment_GetUserDownloadDir(char **result); -int OH_Environment_GetUserDesktopDir(char **result); -int OH_Environment_GetUserDocumentDir(char **result); +int OhEnvironmentGetUserDownloadDir(char **result); +int OhEnvironmentGetUserDesktopDir(char **result); +int OhEnvironmentGetUserDocumentDir(char **result); #ifdef __cplusplus } #endif /* End of #ifdef __cplusplus */ diff --git a/interfaces/kits/c/fileio/fileio.c b/interfaces/kits/c/fileio/fileio.c index 9f2212a05..d8ab8120c 100644 --- a/interfaces/kits/c/fileio/fileio.c +++ b/interfaces/kits/c/fileio/fileio.c @@ -19,7 +19,7 @@ #include "fileio_native.h" #include "../common/error_code.h" -int OH_FileIO_GetFileLocation(char *uri, int uriLength, int *location) +int OhFileIoGetFileLocation(char *uri, int uriLength, int *location) { if (uri == NULL || location == NULL) { return GetErrorCode(-PARAMETER_ERROR); diff --git a/interfaces/kits/c/fileio/fileio.h b/interfaces/kits/c/fileio/fileio.h index 6c75f1252..cbd51b8c5 100644 --- a/interfaces/kits/c/fileio/fileio.h +++ b/interfaces/kits/c/fileio/fileio.h @@ -21,7 +21,7 @@ #ifdef __cplusplus extern "C" { #endif /* End of #ifdef __cplusplus */ -int OH_FileIO_GetFileLocation(char *uri, int uriLength, int *location); +int OhFileIoGetFileLocation(char *uri, int uriLength, int *location); #ifdef __cplusplus } #endif /* End of #ifdef __cplusplus */ diff --git a/interfaces/kits/js/src/mod_environment/environment_n_exporter.cpp b/interfaces/kits/js/src/mod_environment/environment_n_exporter.cpp index 0b87e1edc..fe5aa98b9 100644 --- a/interfaces/kits/js/src/mod_environment/environment_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_environment/environment_n_exporter.cpp @@ -40,7 +40,7 @@ const std::string DOWNLOAD_PATH = "/Download"; const std::string DESKTOP_PATH = "/Desktop"; const std::string DOCUMENTS_PATH = "/Documents"; const std::string DEFAULT_USERNAME = "currentUser"; -const char *g_fileManagerFullMountEnableParameter = "const.filemanager.full_mount.enable"; +const char *FILE_MANAGER_FULL_MOUNT_ENABLE_PARAMETER = "const.filemanager.full_mount.enable"; static bool IsSystemApp() { uint64_t fullTokenId = OHOS::IPCSkeleton::GetCallingFullTokenID(); @@ -77,7 +77,7 @@ static std::string GetPublicPath(const std::string &directoryName) static bool CheckFileManagerFullMountEnable() { char value[] = "false"; - int retSystem = GetParameter(g_fileManagerFullMountEnableParameter, "false", value, sizeof(value)); + int retSystem = GetParameter(FILE_MANAGER_FULL_MOUNT_ENABLE_PARAMETER, "false", value, sizeof(value)); if (retSystem > 0 && !std::strcmp(value, "true")) { return true; } diff --git a/interfaces/kits/js/src/mod_fileio/properties/copy_file.cpp b/interfaces/kits/js/src/mod_fileio/properties/copy_file.cpp index b81501a40..a04c53a94 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/copy_file.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/copy_file.cpp @@ -191,14 +191,14 @@ napi_value CopyFile::Async(napi_env env, napi_callback_info info) return {NVal::CreateUndefined(env)}; }; - const string PROCEDURENAME = "FileIOCopyFile"; + const string procedurename = "FileIOCopyFile"; NVal thisVar(env, funcArg.GetThisVar()); if (funcArg.GetArgc() == NARG_CNT::TWO || (funcArg.GetArgc() == NARG_CNT::THREE && !NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_function))) { - return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURENAME, cbExec, cbCompl).val_; + return NAsyncWorkPromise(env, thisVar).Schedule(procedurename, cbExec, cbCompl).val_; } else { NVal cb(env, funcArg[((funcArg.GetArgc() == NARG_CNT::THREE) ? NARG_POS::THIRD : NARG_POS::FOURTH)]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURENAME, cbExec, cbCompl).val_; + return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedurename, cbExec, cbCompl).val_; } } } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fileio/properties/ftruncate.cpp b/interfaces/kits/js/src/mod_fileio/properties/ftruncate.cpp index 5052a1b23..8d5333d78 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/ftruncate.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/ftruncate.cpp @@ -100,15 +100,14 @@ napi_value Ftruncate::Async(napi_env env, napi_callback_info info) return NVal::CreateUndefined(env); } }; - - const string PROCEDURENAME = "fileIOFtruncate"; + const string procedurename = "fileIOFtruncate"; NVal thisVar(env, funcArg.GetThisVar()); if (funcArg.GetArgc() == NARG_CNT::ONE || (funcArg.GetArgc() == NARG_CNT::TWO && !NVal(env, funcArg[NARG_POS::SECOND]).TypeIs(napi_function))) { - return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURENAME, cbExec, cbComplete).val_; + return NAsyncWorkPromise(env, thisVar).Schedule(procedurename, cbExec, cbComplete).val_; } else { NVal cb(env, funcArg[((funcArg.GetArgc() == NARG_CNT::TWO) ? NARG_POS::SECOND : NARG_POS::THIRD)]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURENAME, cbExec, cbComplete).val_; + return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedurename, cbExec, cbComplete).val_; } } } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp index f648026d3..d21eb0da9 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_entity.cpp @@ -172,7 +172,7 @@ void FileWatcher::ReadNotifyEvent(WatcherCallback callback) while (index < len) { event = reinterpret_cast(buf + index); NotifyEvent(event, callback); - index += sizeof(struct inotify_event) + event->len; + index += static_cast(sizeof(struct inotify_event) + event->len); } } @@ -191,11 +191,11 @@ void FileWatcher::GetNotifyEvent(WatcherCallback callback) while (run_) { int ret = poll(fds, nfds, -1); if (ret > 0) { - if (fds[0].revents & POLLNVAL) { + if (fds[0].revents & static_cast(POLLNVAL)) { run_ = false; return; } - if (fds[1].revents & POLLIN) { + if (fds[1].revents & static_cast(POLLIN)) { ReadNotifyEvent(callback); } } else if (ret < 0 && errno == EINTR) { diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_n_exporter.cpp index 30f49cf5f..268753b30 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/watcher_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/watcher_n_exporter.cpp @@ -180,10 +180,16 @@ void WatcherNExporter::WatcherCallback(napi_env env, NRef &callback, const std:: if (!callback) { HILOGE("Failed to parse watcher callback"); + delete work; return; } JSCallbackContext *callbackContext = new (std::nothrow) JSCallbackContext(callback); + if (callbackContext == nullptr) { + HILOGE("Failed to create JSCallbackContext"); + delete work; + return; + } callbackContext->env_ = env; callbackContext->fileName_ = fileName; callbackContext->event_ = event; diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 1aa3c7465..c7990915d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -131,7 +131,7 @@ void Copy::CheckOrCreatePath(const std::string &destPath) { if (!filesystem::exists(destPath)) { HILOGI("destPath not exist, destPath = %{public}s", destPath.c_str()); - auto file = open(destPath.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + auto file = open(destPath.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (file < 0) { HILOGE("Error opening file descriptor. errno = %{public}d", errno); } @@ -141,9 +141,11 @@ void Copy::CheckOrCreatePath(const std::string &destPath) int Copy::CopyFile(const string &src, const string &dest) { - HILOGD("src = %{public}s, dest = %{public}s", src.c_str(), dest.c_str()); - auto srcFd = open(src.c_str(), O_RDONLY); - auto destFd = open(dest.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + string normalizedSrc = filesystem::weakly_canonical(src).string(); + string normalizedDest = filesystem::weakly_canonical(dest).string(); + HILOGD("src = %{public}s, dest = %{public}s", normalizedSrc.c_str(), normalizedDest.c_str()); + auto srcFd = open(normalizedSrc.c_str(), O_RDONLY); + auto destFd = open(normalizedDest.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (srcFd < 0 || destFd < 0) { HILOGE("Error opening file descriptor. errno = %{public}d", errno); close(srcFd); @@ -471,7 +473,7 @@ void Copy::ReceiveComplete(uv_work_t *work, int stat) return; } NVal obj = NVal::CreateObject(env); - if (processedSize <= numeric_limits::max() && entry->totalSize <= numeric_limits::max()) { + if (processedSize >= 0 && entry->totalSize >= 0) { obj.AddProp("processedSize", NVal::CreateInt64(env, processedSize).val_); obj.AddProp("totalSize", NVal::CreateInt64(env, entry->totalSize).val_); } @@ -629,11 +631,11 @@ void Copy::ReadNotifyEvent(std::shared_ptr infos) infos->exceptionCode = errCode; return; } - if (needContinue && !needSend) { + if (static_cast(needContinue) && !static_cast(needSend)) { index += sizeof(struct inotify_event) + event->len; continue; } - if (callback->progressSize == callback->totalSize) { + if (static_cast(callback->progressSize) == callback->totalSize) { infos->run = false; return; } @@ -663,11 +665,11 @@ void Copy::GetNotifyEvent(std::shared_ptr infos) while (infos->run && infos->exceptionCode == ERRNO_NOERR && infos->eventFd != -1 && infos->notifyFd != -1) { auto ret = poll(fds, nfds, -1); if (ret > 0) { - if (fds[0].revents & POLLNVAL) { + if (fds[0].revents & static_cast(POLLNVAL)) { infos->run = false; return; } - if (fds[1].revents & POLLIN) { + if (fds[1].revents & static_cast(POLLIN)) { ReadNotifyEvent(infos); } } else if (ret < 0 && errno == EINTR) { diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_listener/trans_listener.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_listener/trans_listener.cpp index 2d6f29800..2c72be0f9 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy_listener/trans_listener.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_listener/trans_listener.cpp @@ -176,7 +176,7 @@ void TransListener::CallbackComplete(uv_work_t *work, int stat) return; } NVal obj = NVal::CreateObject(env); - if (entry->progressSize <= numeric_limits::max() && entry->totalSize <= numeric_limits::max()) { + if (entry->progressSize >= 0 && entry->totalSize >= 0) { obj.AddProp("processedSize", NVal::CreateInt64(env, entry->progressSize).val_); obj.AddProp("totalSize", NVal::CreateInt64(env, entry->totalSize).val_); } diff --git a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp index 3df058b85..4cd8bc916 100644 --- a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp +++ b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp @@ -19,6 +19,7 @@ #include #include "filemgmt_libhilog.h" +#include "file_utils.h" #include "uv.h" namespace OHOS { @@ -45,7 +46,7 @@ NAsyncWorkCallback::~NAsyncWorkCallback() return; } - unique_ptr work(new (std::nothrow) uv_work_t); + auto work = CreateUniquePtr(); if (work == nullptr) { HILOGE("Failed to new uv_work_t"); return; -- Gitee