From 1c116aaf53c8b47ec526017f5dc70c692703a82f Mon Sep 17 00:00:00 2001 From: zhouoaoteng Date: Thu, 10 Jul 2025 21:56:41 +0800 Subject: [PATCH] fix:warning Signed-off-by: zhouoaoteng --- .../file_info/napi_file_info_exporter.cpp | 6 ++- .../file_info/napi_file_iterator_exporter.cpp | 40 +++++++-------- .../napi_fileaccess_helper.cpp | 3 +- .../kits/native/recent/recent_n_exporter.cpp | 6 +-- .../trash/src/file_trash_n_exporter.cpp | 49 +++++++++---------- .../main/ets/FileExtensionAbility/Common.ts | 12 ++--- .../FileExtensionAbility.ts | 10 ++-- .../include/holder_manager.h | 3 +- .../src/file_access_service.cpp | 1 + 9 files changed, 66 insertions(+), 64 deletions(-) diff --git a/frameworks/js/napi/file_access_module/file_info/napi_file_info_exporter.cpp b/frameworks/js/napi/file_access_module/file_info/napi_file_info_exporter.cpp index f1d7005c..42232778 100644 --- a/frameworks/js/napi/file_access_module/file_info/napi_file_info_exporter.cpp +++ b/frameworks/js/napi/file_access_module/file_info/napi_file_info_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -96,6 +96,10 @@ static int TransferListFile(const FileInfoEntity* fileInfoEntity, FileIteratorEn HILOG_ERROR("FileInfoEntity is null"); return E_GETRESULT; } + if (fileInfoEntity->fileAccessHelper == nullptr) { + HILOG_ERROR("fileInfoEntity->fileAccessHelper is null"); + return E_GETRESULT; + } fileIteratorEntity->fileAccessHelper = fileInfoEntity->fileAccessHelper; fileIteratorEntity->fileInfo = fileInfoEntity->fileInfo; fileIteratorEntity->offset = 0; diff --git a/frameworks/js/napi/file_access_module/file_info/napi_file_iterator_exporter.cpp b/frameworks/js/napi/file_access_module/file_info/napi_file_iterator_exporter.cpp index b4ebc81e..d7c3845e 100644 --- a/frameworks/js/napi/file_access_module/file_info/napi_file_iterator_exporter.cpp +++ b/frameworks/js/napi/file_access_module/file_info/napi_file_iterator_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -74,15 +74,27 @@ napi_value NapiFileIteratorExporter::Constructor(napi_env env, napi_callback_inf return funcArg.GetThisVar(); } -static int MakeListFileResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileIteratorEntity, - FileInfoEntity *fileInfoEntity, napi_env env, NVal &nVal, bool &isDone) +static bool VerifyArg(FileIteratorEntity *fileIteratorEntity, FileInfoEntity *fileInfoEntity) { if (fileIteratorEntity == nullptr) { HILOG_ERROR("FileIteratorEntity is null"); - return E_GETRESULT; + return false; } if (fileInfoEntity == nullptr) { HILOG_ERROR("FileInfoEntity is null"); + return false; + } + if (fileIteratorEntity->fileAccessHelper == nullptr) { + HILOG_ERROR("fileIteratorEntity->fileAccessHelper is nullptr"); + return false; + } + return true; +} + +static int MakeListFileResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileIteratorEntity, + FileInfoEntity *fileInfoEntity, napi_env env, NVal &nVal, bool &isDone) +{ + if (!VerifyArg(fileIteratorEntity, fileInfoEntity)) { return E_GETRESULT; } SharedMemoryInfo &memInfo = fileIteratorEntity->memInfo; @@ -92,7 +104,6 @@ static int MakeListFileResult(napi_value &objFileInfoExporter, FileIteratorEntit if (ret != ERR_OK) { return ret; } - fileIteratorEntity->offset += fileIteratorEntity->currentDataCounts; ret = fileIteratorEntity->fileAccessHelper->ListFile(fileIteratorEntity->fileInfo, fileIteratorEntity->offset, fileIteratorEntity->filter, memInfo); @@ -119,23 +130,10 @@ static int MakeListFileResult(napi_value &objFileInfoExporter, FileIteratorEntit return ERR_OK; } -static bool VerifyArg(FileIteratorEntity *fileIteratorEntity, FileInfoEntity *fileInfoEntity) -{ - if (fileIteratorEntity == nullptr) { - HILOG_ERROR("FileIteratorEntity is null"); - return true; - } - if (fileInfoEntity == nullptr) { - HILOG_ERROR("FileInfoEntity is null"); - return true; - } - return false; -} - static int MakeScanFileResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileIteratorEntity, FileInfoEntity *fileInfoEntity, napi_env env, NVal &nVal, bool &isDone) { - if (VerifyArg(fileIteratorEntity, fileInfoEntity)) { + if (!VerifyArg(fileIteratorEntity, fileInfoEntity)) { return E_GETRESULT; } std::lock_guard lock(fileIteratorEntity->entityOperateMutex); @@ -184,7 +182,7 @@ static int MakeScanFileResult(napi_value &objFileInfoExporter, FileIteratorEntit static bool FilterTrashAndRecentDir(const std::string &uri) { - HILOG_INFO("FilterTrashAndRecentDir uri: %{public}s", uri.c_str()); + HILOG_INFO("FilterTrashAndRecentDir start"); std::smatch matchResult; return std::regex_match(uri, matchResult, TRASH_RECENT_DIR_REGEX) && matchResult.length() > 0; } @@ -208,7 +206,7 @@ static int GetNextIterator(napi_value &objFileInfoExporter, FileIteratorEntity * return E_GETRESULT; } retNVal = NVal::CreateObject(env); - HILOG_DEBUG("TRASH_DIR or RECENT_DIR: %{public}s", fileInfoEntity->fileInfo.uri.c_str()); + HILOG_DEBUG("GetNextIterator TRASH_DIR or RECENT_DIR"); if (fileIteratorEntity->flag == CALL_LISTFILE) { ret = MakeListFileResult(objFileInfoExporter, fileIteratorEntity, fileInfoEntity, env, retNVal, isDone); } else if (fileIteratorEntity->flag == CALL_SCANFILE) { diff --git a/frameworks/js/napi/file_access_module/napi_fileaccess_helper.cpp b/frameworks/js/napi/file_access_module/napi_fileaccess_helper.cpp index c5c6b940..a4e63513 100644 --- a/frameworks/js/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/frameworks/js/napi/file_access_module/napi_fileaccess_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Huawei Device Co., Ltd. + * Copyright (C) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1241,6 +1241,7 @@ napi_value NAPI_RegisterObserver(napi_env env, napi_callback_info info) FileObserverCallbackWrapper *observerWrapper = static_cast(data); if (observerWrapper != nullptr) { delete observerWrapper; + observerWrapper = nullptr; } }; std::unique_ptr observerWrapper = std::make_unique(); diff --git a/interfaces/kits/native/recent/recent_n_exporter.cpp b/interfaces/kits/native/recent/recent_n_exporter.cpp index 71fc919b..18ee5c83 100644 --- a/interfaces/kits/native/recent/recent_n_exporter.cpp +++ b/interfaces/kits/native/recent/recent_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -192,7 +192,7 @@ static string GetName(const string &path) { auto pos = path.find_last_of('/'); if (pos == string::npos) { - HILOGE("Failed to split filename from path, path: %{private}s", path.c_str()); + HILOGE("Failed to split filename from path."); } return path.substr(pos + 1); } @@ -371,7 +371,7 @@ void RecentNExporter::InitRecentPath() RecentNExporter::recentPath_ = "/storage/Users/" + userName + "/.Recent/"; } } - HILOG_INFO("GetRecentDir %{public}s", RecentNExporter::recentPath_.c_str()); + HILOG_INFO("GetRecentDir end."); } } diff --git a/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp b/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp index dac0d230..6c58c19a 100644 --- a/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp +++ b/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -96,7 +96,7 @@ static string GetTimeSlotFromPath(const string &path) // 获取时间戳目录位置 size_t trashPathWithTimePrefixPos = realFilePathWithTime.find_first_of("/"); if (trashPathWithTimePrefixPos == string::npos) { - HILOG_ERROR("GetTimeSlotFromPath: Invalid path = %{private}s", path.c_str()); + HILOG_ERROR("GetTimeSlotFromPath: Invalid path."); return ""; } string timeSlot = realFilePathWithTime.substr(0, trashPathWithTimePrefixPos); @@ -111,7 +111,7 @@ static int RecursiveFunc(const string &path, vector &dirents) HILOG_ERROR("Failed to request heap memory."); return ENOMEM; } - HILOG_DEBUG("RecursiveFunc: scandir path = %{private}s", path.c_str()); + HILOG_DEBUG("RecursiveFunc: scandir path start"); int num = scandir(path.c_str(), &(pNameList->namelist), FilterFunc, alphasort); if (num < 0) { HILOG_ERROR("RecursiveFunc: Failed to scan dir"); @@ -130,7 +130,7 @@ static int RecursiveFunc(const string &path, vector &dirents) string pathTemp = pathInRecur; pathInRecur += '/' + string((*(pNameList->namelist[i])).d_name); // check if path include TRASH_SUB_DIR + "/", need to add it into dirents - HILOG_DEBUG("RecursiveFunc: pathTemp = %{private}s", pathTemp.c_str()); + HILOG_DEBUG("RecursiveFunc: path include TRASH_SUB_DIR."); string timeSlot = GetTimeSlotFromPath(pathTemp); if (!timeSlot.empty() && pathInRecur.rfind(TRASH_SUB_DIR + timeSlot + "/") != string::npos) { // Only filter previous dir is TRASH_SUB_DIR @@ -189,7 +189,7 @@ static napi_value CreateObjectArray(napi_env env, vector result) static string FindSourceFilePath(const string &path) { - HILOG_INFO("FindSourceFilePath: curFilePath = %{private}s", path.c_str()); + HILOG_INFO("FindSourceFilePath start."); size_t slashSize = 1; // 获取/trash目录位置 size_t trashPathPrefixPos = path.find(FileTrashNExporter::trashPath_); @@ -217,13 +217,13 @@ static string FindSourceFilePath(const string &path) string realFileName = realFilePath.substr(pos + TRASH_SUB_DIR.length() + timeSlot.length() + slashSize); realFilePath = "/" + realFilePathPrefix + realFileName; - HILOG_INFO("FindSourceFilePath: realFilePath After = %{private}s", realFilePath.c_str()); + HILOG_INFO("FindSourceFilePath end."); return realFilePath; } static bool Mkdirs(const string &path, bool isDir, string &newRecoveredPath) { - HILOG_INFO("Mkdirs: path = %{private}s", path.c_str()); + HILOG_INFO("Mkdirs: start."); string recoveredPath = path; string folderName = ""; size_t lastPos = 0; @@ -244,7 +244,7 @@ static bool Mkdirs(const string &path, bool isDir, string &newRecoveredPath) lastPos = i; auto [isExist, ret] = Access(recoveredPath); if (!isExist && !Mkdir(recoveredPath)) { - HILOG_ERROR("Mkdirs fail for %{private}s ", recoveredPath.c_str()); + HILOG_ERROR("Mkdirs failed."); return false; } recoveredPath[i] = '/'; @@ -322,14 +322,14 @@ static int MoveFile(const string &srcFile, const string &destFile) static string RecurCheckIfOnlyContentInDir(const string &path, size_t trashWithTimePos, const string &trashWithTimePath) { - HILOG_INFO("RecurCheckIfOnlyContentInDir: path = %{private}s", path.c_str()); + HILOG_INFO("RecurCheckIfOnlyContentInDir start."); size_t slashPos = path.find_last_of("/"); if (slashPos <= trashWithTimePos) { HILOG_DEBUG("RecurCheckIfOnlyContentInDir: slashPos = %{public}zu", slashPos); return trashWithTimePath; } string parentPath = path.substr(0, slashPos); - HILOG_DEBUG("RecurCheckIfOnlyContentInDir: parentPath = %{private}s", parentPath.c_str()); + HILOG_DEBUG("RecurCheckIfOnlyContentInDir ScanDir start."); int num = ScanDir(parentPath); HILOG_DEBUG("RecurCheckIfOnlyContentInDir: num = %{public}d", num); if (num > 1) { @@ -340,14 +340,14 @@ static string RecurCheckIfOnlyContentInDir(const string &path, size_t trashWithT // 需要向上一层目录判断 return RecurCheckIfOnlyContentInDir(parentPath, trashWithTimePos, trashWithTimePath); } else { - HILOG_ERROR("RecurCheckIfOnlyContentInDir: invalid path = %{private}s", path.c_str()); + HILOG_ERROR("RecurCheckIfOnlyContentInDir: invalid path. "); } return nullptr; } static string GetToDeletePath(const string &toDeletePath, napi_env env) { - HILOG_INFO("GetToDeletePath: toDeletePath = %{private}s", toDeletePath.c_str()); + HILOG_INFO("GetToDeletePath: start."); // 判断是否为有效回收站路径 size_t slashSize = 1; // 获取/Trash目录位置 @@ -463,7 +463,7 @@ napi_value FileTrashNExporter::ListFile(napi_env env, napi_callback_info info) static napi_value RecoverFile(napi_env env, const string &filePath) { string sourceFilePath = FindSourceFilePath(filePath); - HILOG_INFO("RecoverFile: sourceFilePath = %{private}s", sourceFilePath.c_str()); + HILOG_INFO("RecoverFile start."); string newDestPath = sourceFilePath; if (newDestPath.length() == 0 || !Mkdirs(sourceFilePath, false, newDestPath)) { HILOG_ERROR("RecoverFile: Mkdirs failed"); @@ -496,12 +496,10 @@ static napi_value RecoverFile(napi_env env, const string &filePath) static int RecoverFilePart(vector filePathList, map dirPath2UpdatedNameMap) { // 处理文件 + HILOG_INFO("RecoverFilePart start."); for (size_t j = 0; j < filePathList.size(); j++) { string filePath = filePathList[j]; - HILOG_INFO("RecoverFilePart: filePath = %{private}s", filePath.c_str()); string sourceFilePath = FindSourceFilePath(filePath); - HILOG_INFO("RecoverFilePart: sourceFilePath = %{private}s", sourceFilePath.c_str()); - size_t lastSlashPos = sourceFilePath.find_last_of("/"); string fileName = sourceFilePath.substr(lastSlashPos + 1); string sourceFilePathOnly = sourceFilePath.substr(0, lastSlashPos); @@ -523,10 +521,10 @@ static map MakeAndFindUpdateNameDir(vector filterDirPath for (size_t j = 0; j < filterDirPathList.size(); j++) { string dirPath = filterDirPathList[j]; string sourceFilePath = FindSourceFilePath(dirPath); - HILOG_DEBUG("MakeAndFindUpdateNameDir: sourceFilePath = %{private}s", sourceFilePath.c_str()); + HILOG_DEBUG("MakeAndFindUpdateNameDir: Mkdirs begin."); string newDestPath = sourceFilePath; if (Mkdirs(sourceFilePath, true, newDestPath)) { - HILOG_DEBUG("MakeAndFindUpdateNameDir: newDestPath = %{private}s", newDestPath.c_str()); + HILOG_DEBUG("MakeAndFindUpdateNameDir: Mkdirs is true."); if (newDestPath != sourceFilePath) { dirPath2UpdatedNameMap.insert(make_pair(sourceFilePath, newDestPath)); } @@ -604,7 +602,7 @@ napi_value FileTrashNExporter::Recover(napi_env env, napi_callback_info info) return nullptr; } string uriStr = uriPtr.get(); - HILOG_DEBUG("Recover: uriPtr.get() = %{private}s", uriStr.c_str()); + HILOG_DEBUG("Recover: uriPtr get end."); // 获取沙箱目录地址 AppFileService::ModuleFileUri::FileUri fileUri(uriStr); @@ -615,12 +613,11 @@ napi_value FileTrashNExporter::Recover(napi_env env, napi_callback_info info) HILOG_ERROR("Recover: Invalid Path"); return nullptr; } - HILOG_DEBUG("Recover: path = %{private}s", path.c_str()); - + HILOG_DEBUG("Recover: path is trash dir start."); // 判断是否是回收站路径 if (path.find(FileTrashNExporter::trashPath_) == string::npos) { NError(EINVAL).ThrowErr(env); - HILOG_ERROR("Recover: path = %{private}s is not Trash path", path.c_str()); + HILOG_ERROR("Recover: path is not Trash path"); return nullptr; } @@ -661,7 +658,7 @@ napi_value FileTrashNExporter::CompletelyDelete(napi_env env, napi_callback_info } string uriStr = uriPtr.get(); - HILOG_DEBUG("Recover: uriPtr.get() = %{private}s", uriStr.c_str()); + HILOG_DEBUG("Recover: uriPtr get end."); // 获取沙箱目录地址 AppFileService::ModuleFileUri::FileUri fileUri(uriStr); @@ -672,12 +669,12 @@ napi_value FileTrashNExporter::CompletelyDelete(napi_env env, napi_callback_info HILOG_ERROR("Recover: Invalid Path"); return nullptr; } - HILOG_DEBUG("Recover: path = %{private}s", path.c_str()); + HILOG_DEBUG("Recover path is trash dir start."); // 判断是否是回收站路径 if (path.find(FileTrashNExporter::trashPath_) == string::npos) { NError(EINVAL).ThrowErr(env); - HILOG_ERROR("Recover: path = %{private}s is not Trash path", path.c_str()); + HILOG_ERROR("Recover: path is not Trash path"); return nullptr; } @@ -727,7 +724,7 @@ void FileTrashNExporter::InitTrashPath() FileTrashNExporter::trashPath_ = "/storage/Users/" + userName + "/.Trash"; } } - HILOG_INFO("GetRecentDir %{private}s", FileTrashNExporter::trashPath_.c_str()); + HILOG_INFO("GetRecentDir end. "); } } diff --git a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/Common.ts b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/Common.ts index 2bd78c8a..c5a6a9fc 100644 --- a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/Common.ts +++ b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/Common.ts @@ -26,14 +26,14 @@ const FILE_PREFIX_NAME = 'file://'; function checkUri(uri: string): boolean { try { if (uri?.indexOf(FILE_PREFIX_NAME) === 0) { - hilog.info(DOMAIN_CODE, TAG, 'uri is ' + getAnonyString(uri)); + hilog.info(DOMAIN_CODE, TAG, 'uri is ok.'); return true; } else { - hilog.error(DOMAIN_CODE, TAG, 'checkUri failed, uri is ' + getAnonyString(uri)); + hilog.error(DOMAIN_CODE, TAG, 'checkUri failed.'); return false; } } catch (error) { - hilog.error(DOMAIN_CODE, TAG, 'checkUri error, uri is ' + getAnonyString(uri)); + hilog.error(DOMAIN_CODE, TAG, 'checkUri error.'); return false; } } @@ -64,21 +64,21 @@ function getPath(uri): string { let arr = uri.split(sep); let minLength = 2; if (arr.length < minLength) { - hilog.error(DOMAIN_CODE, TAG, 'getPath-parameter-uri format exception, uri is:' + getAnonyString(uri)); + hilog.error(DOMAIN_CODE, TAG, 'getPath error, arr.length < minLength.'); return ''; } let path = uri.replace(arr[0] + sep, ''); if (arr[1].indexOf('/') > 0 && arr[1].split('/')[0] === BUNDLE_NAME) { path = path.replace(arr[1].split('/')[0], ''); } else { - hilog.error(DOMAIN_CODE, TAG, 'getPath-parameter-uri format exception, uri is ' + getAnonyString(uri)); + hilog.error(DOMAIN_CODE, TAG, 'getPath failed'); return ''; } if (path.charAt(path.length - 1) === '/') { path = path.substr(0, path.length - 1); } - hilog.info(DOMAIN_CODE, TAG, 'getPath after ' + getAnonyString(path)); + hilog.info(DOMAIN_CODE, TAG, 'getPath end'); return path; } diff --git a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts index 5622d555..dcd8fd6f 100644 --- a/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts +++ b/services/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -183,7 +183,7 @@ export default class FileExtAbility extends Extension { return uriReturnObject('', E_URIS); } try { - hilog.info(DOMAIN_CODE, TAG, 'createFile, uri is ' + getAnonyString(parentUri)); + hilog.info(DOMAIN_CODE, TAG, 'createFile start.'); let newFileUri = this.genNewFileUri(parentUri, displayName); let path = getPath(newFileUri); if (fs.accessSync(path)) { @@ -223,7 +223,7 @@ export default class FileExtAbility extends Extension { for (let i = 1; i < path.length; ++i) { if (path.charAt(i) === '/') { let subDir = path.substring(0, i); - hilog.info(DOMAIN_CODE, TAG, 'mkdirs: subDir path = ' + subDir); + hilog.info(DOMAIN_CODE, TAG, 'mkdirs start'); try { let isAccess = fs.accessSync(subDir); if (!isAccess) { @@ -695,14 +695,14 @@ export default class FileExtAbility extends Extension { try { // Processing format: The first character is '/' if (selectFileRelativePath !== undefined && selectFileRelativePath.indexOf('/') === 0) { - hilog.info(DOMAIN_CODE, TAG, 'checkRelativePath-path is ' + getAnonyString(selectFileRelativePath)); + hilog.info(DOMAIN_CODE, TAG, 'checkRelativePath-path ok '); return true; } else { - hilog.error(DOMAIN_CODE, TAG, 'checkRelativePath error, path is ' + getAnonyString(selectFileRelativePath)); + hilog.error(DOMAIN_CODE, TAG, 'checkRelativePath error'); return false; } } catch (error) { - hilog.error(DOMAIN_CODE, TAG, 'checkRelativePath error, path is ' + getAnonyString(selectFileRelativePath)); + hilog.error(DOMAIN_CODE, TAG, 'checkRelativePath failed '); return false; } } diff --git a/services/native/file_access_service/include/holder_manager.h b/services/native/file_access_service/include/holder_manager.h index ce2d47c8..33d805c5 100644 --- a/services/native/file_access_service/include/holder_manager.h +++ b/services/native/file_access_service/include/holder_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -95,6 +95,7 @@ public: uint32_t getId(std::function func) { + std::lock_guard guard(holderMutex_); auto haveIter = find_if(holder_.begin(), holder_.end(), [func](const std::pair type) { return func(type.second); diff --git a/services/native/file_access_service/src/file_access_service.cpp b/services/native/file_access_service/src/file_access_service.cpp index 51899a8b..e87c99cf 100644 --- a/services/native/file_access_service/src/file_access_service.cpp +++ b/services/native/file_access_service/src/file_access_service.cpp @@ -91,6 +91,7 @@ void FileAccessService::OnStart() sptr service = FileAccessService::GetInstance(); if (service == nullptr) { HILOG_ERROR("service is nullptr"); + return; } service->Init(); if (!Publish(service)) { -- Gitee