From e4d5d2d4115af66ae80ebe81eb94ed0adfbdbb6b Mon Sep 17 00:00:00 2001 From: chenxi0605 Date: Tue, 12 Aug 2025 15:23:08 +0800 Subject: [PATCH 1/3] clean code Signed-off-by: chenxi0605 --- frameworks/native/backup_ext/src/sub_ext_extension.cpp | 2 +- .../innerkits/native/file_share/src/file_share.cpp | 9 ++++++--- utils/include/b_resources/b_constants.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 4f99ce91e..ff18af6c1 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -152,7 +152,7 @@ void BackupExtExtension::SetClearDataFlag(bool isClearData) string BackupExtExtension::GetBundlePath() { - if (bundleName_ == BConstants::BUNDLE_FILE_MANAGER) { + if (BFile::EndsWith(bundleName_, BConstants::BUNDLE_FILE_MANAGER) && bundleName_.size() == BConstants::FM_LEN) { return string(BConstants::PATH_FILEMANAGE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); } else if (bundleName_ == BConstants::BUNDLE_MEDIAL_DATA) { return string(BConstants::PATH_MEDIALDATA_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 6f6d62b86..79f603158 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -58,7 +58,8 @@ const string FILE_DEFAULT_PATH = "/storage/Users/currentUser/"; const string FILE_PATH_TAIL = "/files/Docs"; const string FILE_PATH_HEAD = "/mnt/hmdfs/"; const string FILE_PATH_MID = "/account/device_view/"; -const string FILE_MANAGER_BUNDLE_NAME = "hmos.filemanager"; +const string FILE_MANAGER_BUNDLE_NAME = ".filemanager"; +const int32_t FM_LEN = 27; } struct FileShareInfo { @@ -101,7 +102,8 @@ static void GetProviderInfo(string uriStr, FileShareInfo &info) Uri uri(uriStr); info.providerBundleName_ = uri.GetAuthority(); info.providerSandboxPath_ = SandboxHelper::Decode(uri.GetPath()); - if (info.providerBundleName_ == DOCS_TYPE && info.targetBundleName_.find(FILE_MANAGER_BUNDLE_NAME) == 0) { + if (info.providerBundleName_ == DOCS_TYPE && bundleName.size() == BConstants::FM_LEN + && BFile::EndsWith(info.targetBundleName_, BConstants::BUNDLE_FILE_MANAGER)) { info.providerSandboxPath_ = FILE_DEFAULT_PATH; } } @@ -254,7 +256,8 @@ static int32_t GetFileShareInfo(const string &uri, uint32_t tokenId, uint32_t fl return ret; } - if (info.providerBundleName_ == DOCS_TYPE && info.targetBundleName_.find(FILE_MANAGER_BUNDLE_NAME) == 0) { + if (info.providerBundleName_ == DOCS_TYPE && bundleName.size() == BConstants::FM_LEN + && BFile::EndsWith(info.targetBundleName_, BConstants::BUNDLE_FILE_MANAGER)) { ret = GetDocsDir(uri, info); if (ret != 0) { LOGE("Failed to get docs dir, errno: %{public}d", ret); diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index a3db60af9..bf66f58f9 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -151,7 +151,7 @@ static inline std::string PATH_PUBLIC_HOME = "/storage/Users/currentUser/"; static inline std::string PATH_APP_DATA = "appdata"; // 文管bundleName -static inline std::string BUNDLE_FILE_MANAGER = "hmos.filemanager"; +static inline std::string BUNDLE_FILE_MANAGER = ".filemanager"; // 文管bundleNameSize constexpr size_t FM_LEN = 27; // 媒体库数据bundleName -- Gitee From a245e88b1350a6f29bf6f81e61be6255f9258b5b Mon Sep 17 00:00:00 2001 From: chenxi0605 Date: Tue, 12 Aug 2025 16:31:13 +0800 Subject: [PATCH 2/3] clean code Signed-off-by: chenxi0605 --- interfaces/common/include/common_func.h | 1 + interfaces/common/src/common_func.cpp | 8 ++++++++ interfaces/innerkits/native/file_share/src/file_share.cpp | 8 ++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/interfaces/common/include/common_func.h b/interfaces/common/include/common_func.h index dffcc8668..1a7e03c53 100644 --- a/interfaces/common/include/common_func.h +++ b/interfaces/common/include/common_func.h @@ -26,6 +26,7 @@ public: static std::string GetSelfBundleName(); static std::string GetUriFromPath(const std::string &path); static bool GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName); + static bool EndsWith(const std::string &str, const std::string &suffix); }; } // namespace AppFileService } // namespace OHOS diff --git a/interfaces/common/src/common_func.cpp b/interfaces/common/src/common_func.cpp index 75c9a466f..94ebf61a8 100644 --- a/interfaces/common/src/common_func.cpp +++ b/interfaces/common/src/common_func.cpp @@ -133,5 +133,13 @@ string CommonFunc::GetUriFromPath(const string &path) realPath = FILE_SCHEME_PREFIX + packageName + SandboxHelper::Encode(realPath); return realPath; } + +bool CommonFunc::EndsWith(const std::string &str, const std::string &suffix) +{ + if (suffix.length() > str.length()) { + return false; + } + return (str.rfind(suffix) == (str.length() - suffix.length())); +} } // namespace AppFileService } // namespace OHOS diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 79f603158..09304a8f0 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -102,8 +102,8 @@ static void GetProviderInfo(string uriStr, FileShareInfo &info) Uri uri(uriStr); info.providerBundleName_ = uri.GetAuthority(); info.providerSandboxPath_ = SandboxHelper::Decode(uri.GetPath()); - if (info.providerBundleName_ == DOCS_TYPE && bundleName.size() == BConstants::FM_LEN - && BFile::EndsWith(info.targetBundleName_, BConstants::BUNDLE_FILE_MANAGER)) { + if (info.providerBundleName_ == DOCS_TYPE && info.targetBundleName_.size() == FM_LEN + && CommonFunc::EndsWith(info.targetBundleName_, BConstants::BUNDLE_FILE_MANAGER)) { info.providerSandboxPath_ = FILE_DEFAULT_PATH; } } @@ -256,8 +256,8 @@ static int32_t GetFileShareInfo(const string &uri, uint32_t tokenId, uint32_t fl return ret; } - if (info.providerBundleName_ == DOCS_TYPE && bundleName.size() == BConstants::FM_LEN - && BFile::EndsWith(info.targetBundleName_, BConstants::BUNDLE_FILE_MANAGER)) { + if (info.providerBundleName_ == DOCS_TYPE && info.targetBundleName_.size() == FM_LEN + && CommonFunc::EndsWith(info.targetBundleName_, BConstants::BUNDLE_FILE_MANAGER)) { ret = GetDocsDir(uri, info); if (ret != 0) { LOGE("Failed to get docs dir, errno: %{public}d", ret); -- Gitee From 2b6a10e66dd51eabaad45225ada27d6ed4a4d206 Mon Sep 17 00:00:00 2001 From: chenxi0605 Date: Tue, 12 Aug 2025 17:18:04 +0800 Subject: [PATCH 3/3] clean code Signed-off-by: chenxi0605 --- interfaces/innerkits/native/file_share/src/file_share.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 09304a8f0..96180a020 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -103,7 +103,7 @@ static void GetProviderInfo(string uriStr, FileShareInfo &info) info.providerBundleName_ = uri.GetAuthority(); info.providerSandboxPath_ = SandboxHelper::Decode(uri.GetPath()); if (info.providerBundleName_ == DOCS_TYPE && info.targetBundleName_.size() == FM_LEN - && CommonFunc::EndsWith(info.targetBundleName_, BConstants::BUNDLE_FILE_MANAGER)) { + && CommonFunc::EndsWith(info.targetBundleName_, FILE_MANAGER_BUNDLE_NAME)) { info.providerSandboxPath_ = FILE_DEFAULT_PATH; } } @@ -257,7 +257,7 @@ static int32_t GetFileShareInfo(const string &uri, uint32_t tokenId, uint32_t fl } if (info.providerBundleName_ == DOCS_TYPE && info.targetBundleName_.size() == FM_LEN - && CommonFunc::EndsWith(info.targetBundleName_, BConstants::BUNDLE_FILE_MANAGER)) { + && CommonFunc::EndsWith(info.targetBundleName_, FILE_MANAGER_BUNDLE_NAME)) { ret = GetDocsDir(uri, info); if (ret != 0) { LOGE("Failed to get docs dir, errno: %{public}d", ret); -- Gitee