From 6c1ea5e3348ec80dd9cb58e7bb161efd7385707a Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Thu, 5 Dec 2024 16:51:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AA=92=E4=BD=93=E5=BA=93uri=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E8=A7=84=E5=88=99=E5=8F=98=E6=9B=B4=E4=B8=BAfuse?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=96=87=E4=BB=B6=E6=8C=87=E5=90=91=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuiruibin --- .../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 a06934ab2..4fc002fad 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -32,6 +32,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://"; @@ -94,6 +95,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; + } { std::lock_guard lock(g_globalMutex); if (BUNDLE_NAME.empty()) { diff --git a/test/unittest/file_uri_native/file_uri_test.cpp b/test/unittest/file_uri_native/file_uri_test.cpp index 8e84576ff..d52248fd4 100644 --- a/test/unittest/file_uri_native/file_uri_test.cpp +++ b/test/unittest/file_uri_native/file_uri_test.cpp @@ -255,6 +255,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