From db67e39b6174a773f87d0edbc8fc41cad653de5e Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Thu, 24 Apr 2025 19:51:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AA=92=E4=BD=93uri=E8=BD=ACpath=E6=96=B0?= =?UTF-8?q?=E8=A7=84=E5=88=99=E9=80=82=E9=85=8D=20Signed-off-by:=20cuiruib?= =?UTF-8?q?in=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../innerkits/native/file_uri/src/file_uri.cpp | 5 +++++ test/unittest/file_uri_native/file_uri_test.cpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp index 11fb261c6..603352432 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -31,6 +31,7 @@ namespace OHOS { namespace AppFileService { namespace ModuleFileUri { const std::string PATH_SHARE = "/data/storage/el2/share"; +const std::string MEDIA_FUSE_PATH_HEAD = "/data/storage/el2/"; const std::string MODE_RW = "/rw/"; const std::string MODE_R = "/r/"; const std::string FILE_SCHEME_PREFIX = "file://"; @@ -91,6 +92,10 @@ string FileUri::GetRealPath() (access(realPath.c_str(), F_OK) == 0 || CheckFileManagerFullMountEnable())) { return realPath; } + if (bundleName == MEDIA_AUTHORITY) { + realPath = MEDIA_FUSE_PATH_HEAD + bundleName + sandboxPath; + return realPath; + } if (((bundleName != "") && (bundleName != CommonFunc::GetSelfBundleName())) || uri_.ToString().find(NETWORK_PARA) != string::npos) { diff --git a/test/unittest/file_uri_native/file_uri_test.cpp b/test/unittest/file_uri_native/file_uri_test.cpp index d02975a69..6c2804c44 100644 --- a/test/unittest/file_uri_native/file_uri_test.cpp +++ b/test/unittest/file_uri_native/file_uri_test.cpp @@ -246,6 +246,23 @@ namespace OHOS::AppFileService::ModuleFileUri { GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0004"; } + /** + * @tc.name: file_uri_test_0005 + * @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_0005, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0005"; + string fileStr = "/data/storage/el2/media/Photo/12/IMG_12345_999999/test.jpg"; + string uri = "file://media/Photo/12/IMG_12345_999999/test.jpg"; + FileUri fileUri(uri); + EXPECT_EQ(fileUri.GetRealPath(), fileStr); + GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0005"; + } /** * @tc.name: file_uri_test_0007 * @tc.desc: Test function of GetFullDirectoryUri() interface for SUCCESS. -- Gitee