From 5f32e72d2b0ed0d599a7b3a119c9f7b985521629 Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Mon, 3 Mar 2025 19:32:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E8=AE=BE=E5=A4=87=E8=B7=A8=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=88=86=E4=BA=AB=EF=BC=8C=E5=8A=A8=E6=80=81=E6=8C=82?= =?UTF-8?q?=E8=BD=BD=E6=B7=BB=E5=8A=A0=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=20Signed-off-by:=20cuiruibin=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/common/include/sandbox_helper.h | 1 + interfaces/common/src/common_func.cpp | 6 +++--- interfaces/common/src/sandbox_helper.cpp | 12 ++++++------ .../innerkits/native/file_share/src/file_share.cpp | 9 +++++++++ .../innerkits/native/file_uri/src/file_uri.cpp | 14 ++++++++++---- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/interfaces/common/include/sandbox_helper.h b/interfaces/common/include/sandbox_helper.h index c0fa99864..91cb0e4b1 100644 --- a/interfaces/common/include/sandbox_helper.h +++ b/interfaces/common/include/sandbox_helper.h @@ -38,6 +38,7 @@ public: static int32_t GetBackupPhysicalPath(const std::string &fileUri, const std::string &userId, std::string &physicalPath); static bool IsValidPath(const std::string &path); + static void GetNetworkIdFromUri(const std::string &fileUri, std::string &networkId); }; } // namespace AppFileService } // namespace OHOS diff --git a/interfaces/common/src/common_func.cpp b/interfaces/common/src/common_func.cpp index cdbe7bfdb..e1a054887 100644 --- a/interfaces/common/src/common_func.cpp +++ b/interfaces/common/src/common_func.cpp @@ -35,7 +35,7 @@ namespace AppFileService { using namespace OHOS::AppExecFwk; namespace { const std::string FILE_SCHEME_PREFIX = "file://"; -const char BACKFLASH = '/'; +const char BACKSLASH = '/'; const std::string FILE_MANAGER_URI_HEAD = "/storage/"; const std::string FILE_MANAGER_AUTHORITY = "docs"; std::string g_bundleName = ""; @@ -101,8 +101,8 @@ static void NormalizePath(string &path) return; } - if (path[0] != BACKFLASH) { - path.insert(0, 1, BACKFLASH); + if (path[0] != BACKSLASH) { + path.insert(0, 1, BACKSLASH); } } diff --git a/interfaces/common/src/sandbox_helper.cpp b/interfaces/common/src/sandbox_helper.cpp index 863884aa0..5b21c2726 100644 --- a/interfaces/common/src/sandbox_helper.cpp +++ b/interfaces/common/src/sandbox_helper.cpp @@ -36,13 +36,13 @@ namespace { const string MOUNT_PATH_MAP_KEY = "mount-path-map"; const string SANDBOX_JSON_FILE_PATH = "/etc/app_file_service/file_share_sandbox.json"; const string BACKUP_SANDBOX_JSON_FILE_PATH = "/etc/app_file_service/backup_sandbox.json"; - const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; - const std::string SHAER_PATH_MID = "/account/cloud_merge_view/files/"; + const std::string SHARE_PATH_HEAD = "/mnt/hmdfs/"; + const std::string SHARE_PATH_MID = "/account/cloud_merge_view/files/"; const string FILE_MANAGER_URI_HEAD = "/storage/"; const string FILE_MANAGER_AUTHORITY = "docs"; const string DLP_MANAGER_BUNDLE_NAME = "com.ohos.dlpmanager"; const string FUSE_URI_HEAD = "/mnt/data/fuse"; - const string BACKFLASH = "/"; + const string BACKSLASH = "/"; const string MEDIA = "media"; const string NETWORK_ID_FLAG = ""; const string LOCAL = "local"; @@ -301,12 +301,12 @@ static int32_t GetMediaPhysicalPath(const std::string &sandboxPath, const std::s return -EINVAL; } - physicalPath = SHAER_PATH_HEAD + userId + SHAER_PATH_MID + mediaUriInfo.mediaType + - BACKFLASH + to_string(bucketNum) + BACKFLASH + mediaUriInfo.realName + mediaSuffix; + physicalPath = SHARE_PATH_HEAD + userId + SHARE_PATH_MID + mediaUriInfo.mediaType + + BACKSLASH + to_string(bucketNum) + BACKSLASH + mediaUriInfo.realName + mediaSuffix; return 0; } -static void GetNetworkIdFromUri(const std::string &fileUri, string &networkId) +void SandboxHelper::GetNetworkIdFromUri(const std::string &fileUri, std::string &networkId) { Uri uri(fileUri); std::string networkIdInfo = uri.GetQuery(); diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 0c954afab..7f2a56163 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -52,6 +52,7 @@ const string SHARE_PATH = "/share/"; const string EXTERNAL_PATH = "file://docs/storage/External"; const string NETWORK_PARA = "networkid="; const int32_t DLP_COMMON = 0; +const std::string BACKSLASH = "/"; } struct FileShareInfo { @@ -141,11 +142,19 @@ static bool CheckIfNeedShare(const string &uriStr, ShareFileType type, FileShare static int32_t GetSharePath(const string &uri, FileShareInfo &info, uint32_t flag) { + string networkId = ""; + SandboxHelper::GetNetworkIdFromUri(uri, networkId); string shareRPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + SHARE_R_PATH + info.providerBundleName_ + info.providerSandboxPath_; string shareRWPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + SHARE_RW_PATH + info.providerBundleName_ + info.providerSandboxPath_; + if (!networkId.empty()) { + string shareRPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + BACKSLASH + + networkId + SHARE_R_PATH + info.providerBundleName_ + info.providerSandboxPath_; + string shareRWPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + BACKSLASH + + networkId + SHARE_RW_PATH + info.providerBundleName_ + info.providerSandboxPath_; + } if (!SandboxHelper::IsValidPath(shareRPath) || !SandboxHelper::IsValidPath(shareRWPath)) { LOGE("Invalid share path"); return -EINVAL; diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp index f2af06226..07da46e9a 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -39,7 +39,7 @@ const std::string FILE_SCHEME_PREFIX = "file://"; const std::string FILE_MANAGER_AUTHORITY = "docs"; const std::string MEDIA_AUTHORITY = "media"; const std::string NETWORK_PARA = "?networkid="; -const std::string BACKFLASH = "/"; +const std::string BACKSLASH = "/"; const std::string FULL_MOUNT_ENABLE_PARAMETER = "const.filemanager.full_mount.enable"; const int DECODE_FORMAT_NUM = 16; const int DECODE_LEN = 2; @@ -132,9 +132,15 @@ string FileUri::GetRealPath() } if (((!bundleName.empty()) && (bundleName != BUNDLE_NAME)) || uri_.ToString().find(NETWORK_PARA) != string::npos) { - realPath = PATH_SHARE + MODE_RW + bundleName + sandboxPath; + string networkId = ""; + SandboxHelper::GetNetworkIdFromUri(uri, networkId); + string pathShare = PATH_SHARE; + if (!networkId.empty()) { + pathShare = PATH_SHARE + BACKSLASH + networkId; + } + realPath = pathShare + MODE_RW + bundleName + sandboxPath; if (access(realPath.c_str(), F_OK) != 0) { - realPath = PATH_SHARE + MODE_R + bundleName + sandboxPath; + realPath = pathShare + MODE_R + bundleName + sandboxPath; } } return realPath; @@ -187,7 +193,7 @@ bool FileUri::IsRemoteUri() { size_t pos = uri_.ToString().find(NETWORK_PARA); if (pos != string::npos && pos > 0 && pos < uri_.ToString().size() - NETWORK_PARA.size()) { - if (uri_.ToString().substr(pos + NETWORK_PARA.size()).find(BACKFLASH) == string::npos) { + if (uri_.ToString().substr(pos + NETWORK_PARA.size()).find(BACKSLASH) == string::npos) { return true; } } -- Gitee