diff --git a/interfaces/kits/c/environment/environment.c b/interfaces/kits/c/environment/environment.c index b5d45da05d409cfdcd3c52fd55bae004a772a4d6..e43bf6a8777d5aeb1b66e11781da50e414918aac 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 c0571a7cd7c55f34272ae767a278d62c811111ce..61f29d86c9bdec13fe6919928fc3203d376b2b43 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 9f2212a05f35fff9caef8048e50d3ec74a348413..d8ab8120cdd6d7b8aeb357d2112e4c13ce2e5eca 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 6c75f12522a7ea5df6d33fe95f5bd43676c2376f..cbd51b8c5ad229cacb009411c38fe052f1a7e89b 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 0b87e1edc93f1aae75306a2b0154183beb207f5f..fe5aa98b9d90de8760d240a50c78b155b0af789e 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 b81501a4055c33930ca8d78dbd4399672d136eb9..a04c53a94c08eb036b9e876799a816f80257186e 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 5052a1b23a2e330bb00774c2efde6de03b1da9b1..8d5333d78970a60866dd238520d0df93b110e15a 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 f648026d389162b5d62c4c958a50f7f6d3e22920..d21eb0da97352099054fdf229f1946b1ae8e3062 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 30f49cf5f93fce107ac5201e719c171790864da4..268753b30e38522a4cd6c7d90bdf81b695a2b225 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 1aa3c7465abc76d673a3eda49cfd416b8059ce07..c7990915da881bbfa67f6d6e663b86193e56a98b 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 2d6f298001502aad3d1742ac6567c996c61f1029..2c72be0f987f201e21f154580d4b73bc3bb3842d 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 3df058b8546c7bbaf23451aaad86018686188ecc..4cd8bc9160b5a1df29535adf36784483c129a93f 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;