diff --git a/interfaces/common/src/common_func.cpp b/interfaces/common/src/common_func.cpp index adde788f73eb19417c2135da56b258dacb28e542..74f715a78e0ae31e13794b07911d3043bd74d213 100644 --- a/interfaces/common/src/common_func.cpp +++ b/interfaces/common/src/common_func.cpp @@ -92,8 +92,8 @@ string CommonFunc::GetUriFromPath(const string &path) NormalizePath(realPath); string packageName = (path.find(FILE_MANAGER_URI_HEAD) == 0) ? FILE_MANAGER_AUTHORITY : GetSelfBundleName(); - realPath = FILE_SCHEME_PREFIX + packageName + realPath; - return SandboxHelper::Encode(realPath); + realPath = FILE_SCHEME_PREFIX + packageName + SandboxHelper::Encode(realPath); + return realPath; } } // namespace AppFileService } // namespace OHOS diff --git a/interfaces/common/src/sandbox_helper.cpp b/interfaces/common/src/sandbox_helper.cpp index 83c18d615ad9a4f33a6c23c7e7273eedf4ceee33..a2d2a390e9998467e5785ebbb4481e54054a88eb 100644 --- a/interfaces/common/src/sandbox_helper.cpp +++ b/interfaces/common/src/sandbox_helper.cpp @@ -62,9 +62,8 @@ std::mutex SandboxHelper::mapMutex_; string SandboxHelper::Encode(const string &uri) { const unordered_set uriCompentsSet = { - ';', ',', '/', '?', ':', '@', '&', - '=', '+', '$', '-', '_', '.', '!', - '~', '*', '(', ')', '#', '\'' + '/', '-', '_', '.', '!', + '~', '*', '(', ')', '\'' }; const int32_t encodeLen = 2; ostringstream outPutStream; @@ -270,7 +269,7 @@ int32_t SandboxHelper::GetPhysicalPath(const std::string &fileUri, const std::st { Uri uri(fileUri); string bundleName = uri.GetAuthority(); - string sandboxPath = uri.GetPath(); + string sandboxPath = SandboxHelper::Decode(uri.GetPath()); if (bundleName == MEDIA) { return GetMediaPhysicalPath(sandboxPath, userId, physicalPath); diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index f7bb27c5262a355fafcc807a9b963f6d959ef6cb..36835e53fe09406c1823a186e769bda51126ebda 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -83,7 +83,7 @@ static void GetProviderInfo(string uriStr, FileShareInfo &info) { Uri uri(uriStr); info.providerBundleName_ = uri.GetAuthority(); - info.providerSandboxPath_ = uri.GetPath(); + info.providerSandboxPath_ = SandboxHelper::Decode(uri.GetPath()); } static bool IsExistDir(const string &path) @@ -204,8 +204,8 @@ static void UmountDelUris(vector sharePathList, string currentUid, strin { string delPathPrefix = DATA_APP_EL2_PATH + currentUid + SHARE_PATH + bundleNameSelf; for (size_t i = 0; i < sharePathList.size(); i++) { - Uri uri(SandboxHelper::Decode(sharePathList[i])); - string path = uri.GetPath(); + Uri uri(sharePathList[i]); + string path = SandboxHelper::Decode(uri.GetPath()); string bundleName = uri.GetAuthority(); string delRPath = delPathPrefix + SHARE_R_PATH + bundleName + path; @@ -247,15 +247,13 @@ static bool NotRequiredBindMount(const FileShareInfo &info, uint32_t flag, const static int32_t CreateSingleShareFile(const string &uri, uint32_t tokenId, uint32_t flag, FileShareInfo &info) { - string decodeUri = SandboxHelper::Decode(uri); - LOGD("CreateShareFile begin with uri %{private}s decodeUri %{private}s", uri.c_str(), decodeUri.c_str()); - + LOGD("CreateShareFile begin with uri %{private}s", uri.c_str()); if (NotRequiredBindMount(info, flag, uri)) { LOGD("Not required to bind mount"); return 0; } - int32_t ret = GetFileShareInfo(decodeUri, tokenId, flag, info); + int32_t ret = GetFileShareInfo(uri, tokenId, flag, info); if (ret != 0) { LOGE("Failed to get FileShareInfo with %{public}d", ret); return ret; diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp index 5327f19a715321311e0bacd08f6cb7ad22afc3cf..4838bf9b166d0f63e9d6c9d1f9e84b6530226f87 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -36,7 +36,7 @@ const std::string MEDIA_AUTHORITY = "media"; const std::string NETWORK_PARA = "?networkid="; string FileUri::GetName() { - string sandboxPath = uri_.GetPath(); + string sandboxPath = SandboxHelper::Decode(uri_.GetPath()); size_t posLast = sandboxPath.find_last_of("/"); if (posLast == string::npos) { return ""; @@ -46,7 +46,7 @@ string FileUri::GetName() return ""; } - return SandboxHelper::Decode(sandboxPath.substr(posLast + 1)); + return sandboxPath.substr(posLast + 1); } string FileUri::GetPath() diff --git a/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp b/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp index d49b0ac97079a832c98a827f8f7d4c6e2be1c75f..d70ee440aaffb334236956436b712bc0f351af35 100644 --- a/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp +++ b/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp @@ -268,8 +268,8 @@ int RemoteFileShare::CreateSharePath(const int &fd, std::string &sharePath, static int GetDistributedPath(Uri &uri, const int &userId, std::string &distributedPath) { - distributedPath = DST_PATH_HEAD + std::to_string(userId) + DST_PATH_MID + - uri.GetAuthority() + REMOTE_SHARE_PATH_DIR + uri.GetPath(); + distributedPath = DST_PATH_HEAD + std::to_string(userId) + DST_PATH_MID + uri.GetAuthority() + + REMOTE_SHARE_PATH_DIR + SandboxHelper::Decode(uri.GetPath()); if (distributedPath.size() >= PATH_MAX) { return -EINVAL; } @@ -333,8 +333,9 @@ static void SetHmdfsUriInfo(struct HmdfsUriInfo &hui, Uri &uri, uint64_t fileSiz std::string path = uri.GetPath(); std::string networkId = NETWORK_PARA + GetLocalNetworkId(); - hui.uriStr = SandboxHelper::Encode(FILE_SCHEME + "://" + bundleName + DISTRIBUTED_DIR_PATH + - REMOTE_SHARE_PATH_DIR + path + networkId); + hui.uriStr = FILE_SCHEME + "://" + bundleName + DISTRIBUTED_DIR_PATH + REMOTE_SHARE_PATH_DIR + + SandboxHelper::Encode(path) + networkId; + hui.fileSize = fileSize; return; } @@ -355,7 +356,7 @@ static int32_t SetPublicDirHmdfsInfo(const std::string &physicalPath, const std: int32_t RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, const int32_t &userId, struct HmdfsUriInfo &hui) { - Uri uri(SandboxHelper::Decode(uriStr)); + Uri uri(uriStr); std::string bundleName = uri.GetAuthority(); LOGD("GetDfsUriFromLocal begin with uri:%{private}s, decode uri:%{private}s", uriStr.c_str(), uri.ToString().c_str());