From 0f897107857d49e6f6bc8d262f01f626403fa58e Mon Sep 17 00:00:00 2001 From: zhouoaoteng Date: Fri, 19 Jul 2024 14:36:52 +0800 Subject: [PATCH] fix: ufs code diff Signed-off-by: zhouoaoteng --- .../src/file_access_ext_stub_impl.cpp | 6 ++-- .../src/js_file_access_ext_ability.cpp | 2 ++ .../kits/native/recent/recent_n_exporter.cpp | 10 +++--- .../trash/src/file_trash_n_exporter.cpp | 9 ++--- interfaces/kits/picker/picker.js | 5 ++- .../FileExtensionAbility.ts | 34 ++++++++----------- .../include/file_access_service.h | 4 +-- .../include/file_access_service_proxy.h | 4 +-- .../include/file_access_service_stub.h | 4 +-- .../include/ifile_access_service_base.h | 4 +-- .../include/iobserver_callback.h | 4 +-- .../src/file_access_service.cpp | 2 +- .../src/file_access_service_stub.cpp | 2 +- .../src/observer_callback_proxy.cpp | 2 +- utils/file_access_check_util.h | 4 +-- 15 files changed, 47 insertions(+), 49 deletions(-) diff --git a/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp b/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp index a6bcccc1..2a2b19a0 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 - 2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -134,8 +134,8 @@ int FileAccessExtStubImpl::Rename(const Uri &sourceFile, const std::string &disp return ret; } -int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter, - SharedMemoryInfo &memInfo) +int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offset, + const FileFilter &filter, SharedMemoryInfo &memInfo) { UserAccessTracer trace; trace.Start("ListFile"); diff --git a/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp b/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp index 1c0aabf7..eb0f6b4c 100644 --- a/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp +++ b/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp @@ -1562,6 +1562,7 @@ napi_value JsFileAccessExtAbility::FuncCallback(napi_env env, napi_callback_info HILOG_ERROR("napi_get_cb_info fail."); return GetUndefinedValue(env); } + if (argc != ARGC_TWO) { HILOG_ERROR("invalid args."); return GetUndefinedValue(env); @@ -1748,6 +1749,7 @@ napi_status JsFileAccessExtAbility::GetFileInfoFromJs(napi_env &env, napi_value HILOG_ERROR("Convert mimeType fail"); return napi_generic_failure; } + return napi_ok; } diff --git a/interfaces/kits/native/recent/recent_n_exporter.cpp b/interfaces/kits/native/recent/recent_n_exporter.cpp index 8bc3b29e..77bc688f 100644 --- a/interfaces/kits/native/recent/recent_n_exporter.cpp +++ b/interfaces/kits/native/recent/recent_n_exporter.cpp @@ -35,7 +35,7 @@ using namespace LibN; using namespace AppFileService::ModuleFileUri; using namespace FileAccessFwk; -static std::mutex recentPathMutex; +static std::mutex g_recentPathMutex; static bool CheckPermission(const std::string &permission) { Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); @@ -190,7 +190,8 @@ static tuple CheckRealFileExist(const string &recentFilePath) HILOG_ERROR("Failed to stat file, errno=%{public}d", errno); return { errno, statBuf }; } - string oldRecentFilePath = RecentNExporter::recentPath_ + to_string(statBuf.st_dev) + "_" + to_string(statBuf.st_ino); + string oldRecentFilePath = + RecentNExporter::recentPath_ + to_string(statBuf.st_dev) + "_" + to_string(statBuf.st_ino); if (oldRecentFilePath == recentFilePath) { return { 0, statBuf }; } @@ -278,7 +279,8 @@ static napi_value ListFileCore(napi_env env) NError(ENOMEM).ThrowErr(env); return nullptr; } - pNameList->direntNum = scandir(RecentNExporter::recentPath_.c_str(), &(pNameList->namelist), FilterFunc, SortReceneFile); + pNameList->direntNum = scandir(RecentNExporter::recentPath_.c_str(), + &(pNameList->namelist), FilterFunc, SortReceneFile); if (pNameList->direntNum < 0) { HILOG_ERROR("Failed to scan dir, errno=%{public}d", errno); NError(errno).ThrowErr(env); @@ -320,7 +322,7 @@ string RecentNExporter::GetClassName() void RecentNExporter::InitRecentPath() { if (RecentNExporter::recentPath_.empty()) { - std::unique_lock lock(recentPathMutex); + std::unique_lock lock(g_recentPathMutex); if (!RecentNExporter::recentPath_.empty()) { return ; } 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 6f10cbad..69ae0ac8 100644 --- a/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp +++ b/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp @@ -38,7 +38,7 @@ using namespace FileManagement; using namespace std; using namespace FileAccessFwk; -static std::mutex trashPathMutex; +static std::mutex g_trashPathMutex; static bool CheckCallingPermission(const std::string &permission) { @@ -331,7 +331,8 @@ static string GetToDeletePath(const string &toDeletePath, napi_env env) NError(EINVAL).ThrowErr(env); return nullptr; } - string realFilePathWithTime = toDeletePath.substr(trashPathPrefixPos + FileTrashNExporter::trashPath_.length() + slashSize); + string realFilePathWithTime = + toDeletePath.substr(trashPathPrefixPos + FileTrashNExporter::trashPath_.length() + slashSize); // 获取时间戳目录位置 size_t trashPathWithTimePrefixPos = realFilePathWithTime.find_first_of("/"); size_t realTimeDirPos = trashPathPrefixPos + FileTrashNExporter::trashPath_.length() + @@ -546,7 +547,7 @@ static napi_value RecoverDir(napi_env env, const string &dirPath) HILOG_ERROR("RecoverFilePart: Failed to Recover File in Dir."); return nullptr; } - + // 删除目录 auto err = RmDirent(GetToDeletePath(dirPath, env)); if (err) { @@ -691,7 +692,7 @@ string FileTrashNExporter::GetClassName() void FileTrashNExporter::InitTrashPath() { if (FileTrashNExporter::trashPath_.empty()) { - std::unique_lock lock(trashPathMutex); + std::unique_lock lock(g_trashPathMutex); if (!FileTrashNExporter::trashPath_.empty()) { return ; } diff --git a/interfaces/kits/picker/picker.js b/interfaces/kits/picker/picker.js index 3a064a84..3ff7d7dd 100644 --- a/interfaces/kits/picker/picker.js +++ b/interfaces/kits/picker/picker.js @@ -40,7 +40,7 @@ const ExtTypes = { }; const PickerDetailType = { - FILE_MGR_AUTH: 'downloadAuth', + FILE_MGR_AUTH: 'downloadAuth', FILE_MGR_SELECT:'select', FILE_MGR_SAVE:'save', }; @@ -267,7 +267,6 @@ function parseDocumentPickerSelectOption(args, action) { return config; } - function parseAudioPickerSelectOption(args, action) { let config = { action: action, @@ -420,7 +419,7 @@ function getDocumentPickerSaveResult(args) { if (args.ability_params_stream) { saveResult.data = args.ability_params_stream; saveResult.error = args.resultCode; - if (args.userSuffixIndex) { + if (args.userSuffixIndex >= 0) { saveResult.suffix = args.userSuffixIndex; } } 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 5798e8af..1a16573b 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 @@ -21,7 +21,7 @@ import fileExtensionInfo from '@ohos.file.fileExtensionInfo'; import hilog from '@ohos.hilog'; import { getFileInfos, buildFilterOptions, buildNoFilterOptions, hasFilter } from './ListScanFileInfo'; import type { Fileinfo } from './Common'; -import { getPath, checkUri, encodePathOfUri, decodeUri, uriReturnObject, BUNDLE_NAME, DOMAIN_CODE, fileinfoReturnObject } from './Common'; +import { getPath, checkUri, uriReturnObject, encodePathOfUri, decodeUri, BUNDLE_NAME, DOMAIN_CODE, fileinfoReturnObject } from './Common'; import { FILE_PREFIX_NAME, TAG, fdReturnObject, boolReturnObject, rootsReturnObject } from './Common'; import { infosReturnObject, resultsResultObject } from './Common'; @@ -98,6 +98,7 @@ export default class FileExtAbility extends Extension { hilog.info(DOMAIN_CODE, TAG, 'Extension init process'); } + genNewFileUri(uri, displayName) { let newFileUri = uri; if (uri.charAt(uri.length - 1) === '/') { @@ -196,7 +197,7 @@ export default class FileExtAbility extends Extension { hilog.info(DOMAIN_CODE, TAG, 'createFile, uri is ' + parentUri); let newFileUri = this.genNewFileUri(parentUri, displayName); let path = getPath(newFileUri); - if(fs.accessSync(path)) { + if (fs.accessSync(path)) { return uriReturnObject('', E_EXIST); } let file = fs.openSync(path, fs.OpenMode.CREATE); @@ -253,7 +254,7 @@ export default class FileExtAbility extends Extension { if (path.indexOf(USER_PATH) !== 0) { return CURRENT_USER_PATH; } - for (i = 0;i < path.length; i++) { + for (i = 0; i < path.length; i++) { if (path[i] === '/') { num ++; if (num === CURRENT_USER_PATH_LEN) { @@ -871,7 +872,7 @@ export default class FileExtAbility extends Extension { }; } else { if (res) { - console.info("file exists"); + console.info('file exists'); } } }); @@ -896,9 +897,9 @@ export default class FileExtAbility extends Extension { } isDeviceUri(uri): boolean { - let tempUri = uri.slice(0, uri.lastIndexOf('/')) - let deviceUris = fileAccess.DeviceRoots - if (deviceUris.indexOf(tempUri) != -1) { + let tempUri = uri.slice(0, uri.lastIndexOf('/')); + let deviceUris = fileAccess.DeviceRoots; + if (deviceUris.indexOf(tempUri) !== -1) { return true; } return false; @@ -955,11 +956,11 @@ export default class FileExtAbility extends Extension { if (!observerMap.has(uri)) { return E_GETRESULT; } - let watcher = observerMap.get(uri); - if (typeof watcher !== undefined) { - watcher.stop(); - observerMap.delete(uri); - } + let watcher = observerMap.get(uri); + if (typeof watcher !== undefined) { + watcher.stop(); + observerMap.delete(uri); + } } catch (e) { hilog.error(DOMAIN_CODE, TAG, 'stopWatcher error ' + e.message); return E_GETRESULT; @@ -1031,7 +1032,6 @@ export default class FileExtAbility extends Extension { hilog.error(DOMAIN_CODE, TAG, 'check arguments error, invalid arguments'); return this.getReturnValue(sourceFileUri, targetParentUri, E_URIS, EXCEPTION); } - let displayName = this.getFileName(sourceFileUri); let newFileUri = this.genNewFileUri(targetParentUri, displayName); let newPathDir = getPath(targetParentUri); @@ -1042,27 +1042,21 @@ export default class FileExtAbility extends Extension { return this.getReturnValue(sourceFileUri, targetParentUri, E_URIS, EXCEPTION); } if (oldPath === newPath) { - // move to the same directory return this.getReturnValue(sourceFileUri, newFileOrDirUri, ERR_OK, '', EXCEPTION); } else if (newPath.indexOf(oldPath) === 0 && newPath.charAt(oldPath.length) === '/') { - // move to a subdirectory of the source directory return this.getReturnValue(sourceFileUri, targetParentUri, E_GETRESULT, '', NOEXCEPTION); } - try { - // The source file does not exist or the destination is not a directory let stat = fs.statSync(getPath(targetParentUri)); let statOld = fs.statSync(oldPath); if (!fs.accessSync(oldPath) || !stat || !stat.isDirectory() || !statOld) { hilog.error(DOMAIN_CODE, TAG, 'operate illegal'); return this.getReturnValue(sourceFileUri, targetParentUri, E_GETRESULT, '', EXCEPTION); } - if (statOld.isFile()) { hilog.info(DOMAIN_CODE, TAG, 'sourceUri is file'); let isExist = fs.accessSync(newPath); if (isExist && fs.statSync(newPath).isDirectory()) { - hilog.info(DOMAIN_CODE, TAG, 'dst is dir'); return this.getReturnValue(sourceFileUri, newFileUri, E_IS_DIR, '', NOEXCEPTION); } if (isExist && force === false) { @@ -1136,4 +1130,4 @@ export default class FileExtAbility extends Extension { return uriReturnObject('', e.code); } } -}; \ No newline at end of file +}; diff --git a/services/native/file_access_service/include/file_access_service.h b/services/native/file_access_service/include/file_access_service.h index 4f92ab43..5d4984c2 100644 --- a/services/native/file_access_service/include/file_access_service.h +++ b/services/native/file_access_service/include/file_access_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (C) 2023-2024 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 @@ -288,4 +288,4 @@ private: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // FILE_ACCESS_SERVICE_H \ No newline at end of file +#endif // FILE_ACCESS_SERVICE_H diff --git a/services/native/file_access_service/include/file_access_service_proxy.h b/services/native/file_access_service/include/file_access_service_proxy.h index c938a9bc..8233430d 100644 --- a/services/native/file_access_service/include/file_access_service_proxy.h +++ b/services/native/file_access_service/include/file_access_service_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -70,4 +70,4 @@ private: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // FILE_ACCESS_SERVICE_PROXY_H \ No newline at end of file +#endif // FILE_ACCESS_SERVICE_PROXY_H diff --git a/services/native/file_access_service/include/file_access_service_stub.h b/services/native/file_access_service/include/file_access_service_stub.h index cc01c4e4..94823f82 100644 --- a/services/native/file_access_service/include/file_access_service_stub.h +++ b/services/native/file_access_service/include/file_access_service_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -44,4 +44,4 @@ private: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // FILE_ACCESS_SERVICE_STUB_H \ No newline at end of file +#endif // FILE_ACCESS_SERVICE_STUB_H diff --git a/services/native/file_access_service/include/ifile_access_service_base.h b/services/native/file_access_service/include/ifile_access_service_base.h index fc0c44d2..f9748567 100644 --- a/services/native/file_access_service/include/ifile_access_service_base.h +++ b/services/native/file_access_service/include/ifile_access_service_base.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -41,4 +41,4 @@ protected: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // I_FILE_ACCESS_SERVICE_BASE_H \ No newline at end of file +#endif // I_FILE_ACCESS_SERVICE_BASE_H diff --git a/services/native/file_access_service/include/iobserver_callback.h b/services/native/file_access_service/include/iobserver_callback.h index bf8c327f..a55d3b0e 100644 --- a/services/native/file_access_service/include/iobserver_callback.h +++ b/services/native/file_access_service/include/iobserver_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 @@ -34,4 +34,4 @@ public: }; } // namespace FileAccessFwk } // namespace OHOS -#endif // I_FILE_ACCESS_OBSERVER_H \ No newline at end of file +#endif // I_FILE_ACCESS_OBSERVER_H 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 46d204ac..3b633400 100644 --- a/services/native/file_access_service/src/file_access_service.cpp +++ b/services/native/file_access_service/src/file_access_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (C) 2023-2024 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 diff --git a/services/native/file_access_service/src/file_access_service_stub.cpp b/services/native/file_access_service/src/file_access_service_stub.cpp index 1ffe1759..96a54018 100644 --- a/services/native/file_access_service/src/file_access_service_stub.cpp +++ b/services/native/file_access_service/src/file_access_service_stub.cpp @@ -213,4 +213,4 @@ ErrCode FileAccessServiceStub::CmdGetExensionProxy(MessageParcel &data, MessageP return ERR_OK; } } // namespace FileAccessFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/native/file_access_service/src/observer_callback_proxy.cpp b/services/native/file_access_service/src/observer_callback_proxy.cpp index d01d3ad1..f536ee79 100644 --- a/services/native/file_access_service/src/observer_callback_proxy.cpp +++ b/services/native/file_access_service/src/observer_callback_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2023 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 diff --git a/utils/file_access_check_util.h b/utils/file_access_check_util.h index 9d02f588..fd02c394 100644 --- a/utils/file_access_check_util.h +++ b/utils/file_access_check_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -26,4 +26,4 @@ return returnContext; \ } -#endif // FILE_ACCESS_UTIL_H \ No newline at end of file +#endif // FILE_ACCESS_UTIL_H -- Gitee