diff --git a/interfaces/common/include/sandbox_helper.h b/interfaces/common/include/sandbox_helper.h index c0fa998645d74655d45b4bf536b5b631e802e5ef..91cb0e4b11dbd887e70648f4ccfe174821a8918f 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 cdbe7bfdbb244ee31c36700ffdc853ecf4d5ced1..e1a0548876628c195942d6fd1a81ea97c241ccfa 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 863884aa02dbe43c97f73c9a4cc32ba784b26b9a..5b21c2726a150ed8ba024ca0e9f14ec41475c443 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 0c954afab138b08e587e71fc7134a8fa4b4c3ca9..7f2a56163607ec95b87b3b5e7209633d1256aace 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 f2af06226bd36679c74b318409e3cd9e0b36ca15..07da46e9a4ef3b453130511553da5358eaeac5bc 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; } }