diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 36491aafb0d985b09c61268fdbbd5f5ea46f9458..20df5c5550a0238141fc37f62589b87d982b0d3b 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -167,10 +167,10 @@ static int32_t GetSharePath(const string &uri, FileShareInfo &info, uint32_t fla SHARE_RW_PATH + info.providerBundleName_ + info.providerSandboxPath_; if (!networkId.empty()) { - shareRPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + BACKSLASH + - networkId + SHARE_R_PATH + info.providerBundleName_ + info.providerSandboxPath_; - shareRWPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + BACKSLASH + - networkId + SHARE_RW_PATH + info.providerBundleName_ + info.providerSandboxPath_; + shareRPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + SHARE_R_PATH + + networkId + BACKSLASH + info.providerBundleName_ + info.providerSandboxPath_; + shareRWPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + SHARE_RW_PATH + + networkId + BACKSLASH + info.providerBundleName_ + info.providerSandboxPath_; } if (!SandboxHelper::IsValidPath(shareRPath) || !SandboxHelper::IsValidPath(shareRWPath)) { LOGE("Invalid share path"); diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp index b7674f81e6beeb29833a16a0cd1522d6930a13e5..cc229ca47aa40c52af29aa12773c984151b6afbc 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -134,13 +134,17 @@ string FileUri::GetRealPath() uri_.ToString().find(NETWORK_PARA) != string::npos) { string networkId = ""; SandboxHelper::GetNetworkIdFromUri(uri_.ToString(), networkId); - string pathShare = PATH_SHARE; if (!networkId.empty()) { - pathShare = PATH_SHARE + BACKSLASH + networkId; + realPath = PATH_SHARE + MODE_RW + networkId + BACKSLASH + bundleName + sandboxPath; + } else { + realPath = PATH_SHARE + MODE_RW + bundleName + sandboxPath; } - realPath = pathShare + MODE_RW + bundleName + sandboxPath; if (access(realPath.c_str(), F_OK) != 0) { - realPath = pathShare + MODE_R + bundleName + sandboxPath; + if (!networkId.empty()) { + realPath = PATH_SHARE + MODE_R + networkId + BACKSLASH + bundleName + sandboxPath; + } else { + realPath = PATH_SHARE + MODE_R + bundleName + sandboxPath; + } } } LOGD("GetRealPath return path is ,%{private}s", realPath.c_str()); diff --git a/test/unittest/file_uri_native/file_uri_test.cpp b/test/unittest/file_uri_native/file_uri_test.cpp index 468865cb2ce06090438a413ac7b85f1cbef7abe9..44daa38423ca10b36d26d7fef101d7e0ee484307 100644 --- a/test/unittest/file_uri_native/file_uri_test.cpp +++ b/test/unittest/file_uri_native/file_uri_test.cpp @@ -272,6 +272,40 @@ namespace OHOS::AppFileService::ModuleFileUri { EXPECT_EQ(fileUri.GetRealPath(), fileStr); GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0005"; } + /** + * @tc.name: file_uri_test_00011 + * @tc.desc: Test function of GetPath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7LW57 + */ + HWTEST_F(FileUriTest, File_uri_GetPath_0009, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0009"; + string uri = "file://docs/storage/Users/currentUser/Documents/1.txt?networkid=***"; + string fileStr = "/data/storage/el2/share/r/***/docs/storage/Users/currentUser/Documents/1.txt"; + FileUri fileUri(uri); + EXPECT_EQ(fileUri.GetRealPath(), fileStr); + GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0009"; + } + /** + * @tc.name: file_uri_test_00012 + * @tc.desc: Test function of GetPath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7LW57 + */ + HWTEST_F(FileUriTest, File_uri_GetPath_0010, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0010"; + string uri = "file://docs/storage/Users/currentUser/Documents/1.txt?networkid="; + string fileStr = "/data/storage/el2/share/r/docs/storage/Users/currentUser/Documents/1.txt"; + FileUri fileUri(uri); + EXPECT_EQ(fileUri.GetRealPath(), fileStr); + GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0010"; + } /** * @tc.name: File_uri_GetPathBySA_0001 diff --git a/test/unittest/file_uri_ndk_test/file_uri_ndk_test.cpp b/test/unittest/file_uri_ndk_test/file_uri_ndk_test.cpp index 95c2c0d421cf8b67129a124fdddf1a03718385c0..2e80653f4d8e27972632c802c3e816a947bdf2cb 100644 --- a/test/unittest/file_uri_ndk_test/file_uri_ndk_test.cpp +++ b/test/unittest/file_uri_ndk_test/file_uri_ndk_test.cpp @@ -153,7 +153,7 @@ HWTEST_F(NDKFileUriTest, get_path_from_uri_test_004, TestSize.Level1) fileUriStr += "?networkid=64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9"; const char *fileUri = fileUriStr.c_str(); std::string filePathStr = - "/data/storage/el2/share/64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9/r/" + BUNDLE_A + + "/data/storage/el2/share/r/64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9/" + BUNDLE_A + "/data/storage/el2/distributedfiles/.remote_share/"; filePathStr += "data/storage/el2/base/haps/entry/files/GetPathFromUri004.txt"; const char *filePath = filePathStr.c_str(); @@ -182,7 +182,7 @@ HWTEST_F(NDKFileUriTest, get_path_from_uri_test_005, TestSize.Level1) fileUriStr += "?networkid=64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9"; const char *fileUri = fileUriStr.c_str(); const char filePath[] = - "/data/storage/el2/share/64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9/r/docs/storage/Users/" + "/data/storage/el2/share/r/64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9/docs/storage/Users/" "currentUser/Documents/GetPathFromUri005.txt"; char *result = nullptr; unsigned int length = fileUriStr.size(); @@ -211,7 +211,7 @@ HWTEST_F(NDKFileUriTest, get_path_from_uri_test_006, TestSize.Level1) fileUriStr += "?networkid=64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9"; const char *fileUri = fileUriStr.c_str(); std::string filePathUri = - "/data/storage/el2/share/64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9/r/" + bundleB; + "/data/storage/el2/share/r/64799ecdf70788e396f454ff4a6e6ae4b09e20227c39c21f6e67a2aacbcef7b9/" + bundleB; filePathUri += "/data/storage/el2/distributedfiles/.remote_share/"; filePathUri += "data/storage/el2/base/haps/entry/files/GetPathFromUri006.txt"; const char *filePath = filePathUri.c_str();