From 0a8db7805661b77fb9559db136cdf024f2cd2469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E4=BD=B3=E7=82=9C?= Date: Wed, 10 Sep 2025 20:32:47 +0800 Subject: [PATCH 1/2] delete ioctl get path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 石佳炜 --- .../include/remote_file_share.h | 4 - .../src/remote_file_share.cpp | 194 +-------- .../remote_file_share_test.cpp | 403 ------------------ 3 files changed, 1 insertion(+), 600 deletions(-) diff --git a/interfaces/innerkits/native/remote_file_share/include/remote_file_share.h b/interfaces/innerkits/native/remote_file_share/include/remote_file_share.h index e934ed6aa..4afd4d594 100644 --- a/interfaces/innerkits/native/remote_file_share/include/remote_file_share.h +++ b/interfaces/innerkits/native/remote_file_share/include/remote_file_share.h @@ -37,10 +37,6 @@ public: RemoteFileShare() {} static int CreateSharePath(const int &fd, std::string &sharePath, const int &userId, const std::string &deviceId = SHARE_ALL_DEVICE); - static int32_t GetDfsUriFromLocal(const std::string &uriStr, const int32_t &userId, struct HmdfsUriInfo &hui); - static int32_t GetDfsUrisFromLocal(const std::vector &uriList, - const int32_t &userId, - std::unordered_map &uriToDfsUriMaps); static int32_t GetDfsUrisDirFromLocal(const std::vector &uriList, const int32_t &userId, std::unordered_map &uriToDfsUriMaps); static int32_t TransRemoteUriToLocal(const std::vector &uriList, 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 f888fa9ae..9d8de33b3 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 @@ -278,22 +278,6 @@ int RemoteFileShare::CreateSharePath(const int &fd, return E_OK; } -static int GetDistributedPath(Uri &uri, - const int &userId, - std::string &distributedPath, - const std::string &bundleName, - const std::string &networkId) -{ - distributedPath = DST_PATH_HEAD + std::to_string(userId) + DST_PATH_MID + bundleName + REMOTE_SHARE_PATH_DIR + - BACKSLASH + networkId + SandboxHelper::Decode(uri.GetPath()); - if (distributedPath.size() >= PATH_MAX) { - LOGE("Path is too long with %{public}zu", distributedPath.size()); - return -EINVAL; - } - - return E_OK; -} - static int GetMediaDistributedDir(const int &userId, std::string &distributedDir, const std::string &networkId) { distributedDir = DST_PATH_HEAD + std::to_string(userId) + DST_PATH_MID + MEDIA_BUNDLE_NAME + @@ -403,23 +387,6 @@ static std::string GetPhysicalPath(Uri &uri, const std::string &userId) return physicalPath; } -static void InitHmdfsInfo(struct HmdfsDstInfo &hdi, - const std::string &physicalPath, - const std::string &distributedPath, - const std::string &bundleName) -{ - hdi.localLen = physicalPath.size() + 1; - hdi.localPathIndex = reinterpret_cast(physicalPath.c_str()); - - hdi.distributedLen = distributedPath.size() + 1; - hdi.distributedPathIndex = reinterpret_cast(distributedPath.c_str()); - - hdi.bundleNameLen = bundleName.size() + 1; - hdi.bundleNameIndex = reinterpret_cast(bundleName.c_str()); - - hdi.size = reinterpret_cast(&hdi.size); -} - static std::string GetLocalNetworkId() { const std::string LOCAL = "local"; @@ -480,75 +447,11 @@ static int32_t SetPublicDirHmdfsInfo(const std::string &physicalPath, const std: return E_OK; } -static int32_t GetMergePathFd(HmdfsDstInfo &hdi, UniqueFd &dirFd, const int32_t &userId) -{ - LOGI("Open merge path start"); - std::string ioctlDir = SHARE_PATH_HEAD + std::to_string(userId) + SHARE_PATH_MID; - UniqueFd dirMergeFd(open(ioctlDir.c_str(), O_RDONLY)); - if (dirFd < 0) { - LOGE("Open merge path failed with %{public}d", errno); - return errno; - } - int32_t ret = ioctl(dirMergeFd, HMDFS_IOC_GET_DST_PATH, &hdi); - if (ret != E_OK) { - LOGE("Ioctl merge failed with %{public}d", errno); - return -errno; - } - dirFd = std::move(dirMergeFd); - return E_OK; -} - -int32_t RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, const int32_t &userId, struct HmdfsUriInfo &hui) -{ - LOGI("GetDfsUriFromLocal start"); - Uri uri(uriStr); - std::string bundleName = uri.GetAuthority(); - std::string physicalPath = GetPhysicalPath(uri, std::to_string(userId)); - if (physicalPath == "") { - LOGE("Failed to get physical path"); - return -EINVAL; - } - if (bundleName == MEDIA_AUTHORITY) { - bundleName = MEDIA_BUNDLE_NAME; - } - - std::string networkId = GetLocalNetworkId(); - if (bundleName == FILE_MANAGER_AUTHORITY) { - (void)SetPublicDirHmdfsInfo(physicalPath, uriStr, hui, networkId); - LOGD("GetDfsUriFromLocal successfully"); - return E_OK; - } - - std::string distributedPath; - int ret = GetDistributedPath(uri, userId, distributedPath, bundleName, networkId); - if (ret != E_OK) { - return ret; - } - - struct HmdfsDstInfo hdi; - InitHmdfsInfo(hdi, physicalPath, distributedPath, bundleName); - LOGI("open ioctlDir Create ioctl start"); - std::string ioctlDir = SHARE_PATH_HEAD + std::to_string(userId) + LOWER_SHARE_PATH_MID; - UniqueFd dirFd(open(ioctlDir.c_str(), O_RDONLY)); - if (dirFd < 0) { - LOGE("Open share path failed with %{public}d", errno); - return errno; - } - - ret = ioctl(dirFd, HMDFS_IOC_GET_DST_PATH, &hdi); - if (ret != E_OK && GetMergePathFd(hdi, dirFd, userId) != E_OK) { - return errno; - } - SetHmdfsUriInfo(hui, uri, hdi.size, networkId, bundleName); - LOGI("GetDfsUriFromLocal successfully"); - return E_OK; -} - static int32_t UriCategoryByType(const std::vector &uriList, std::vector &mediaUriList, std::vector &otherUriList) { - LOGI("GetDfsUrisFromLocal UriCategoryByType start"); + LOGI("GetDfsUrisDirFromLocal UriCategoryByType start"); if (uriList.size() == 0) { LOGE("Parameter uriList is NULL"); return -EINVAL; @@ -565,101 +468,6 @@ static int32_t UriCategoryByType(const std::vector &uriList, return E_OK; } -static int32_t GetMediaDfsUrisFromLocal(const std::vector &uriList, - const int32_t &userId, - std::unordered_map &uriToDfsUriMaps) -{ - LOGI("GetMediaDfsUrisFromLocal start"); - std::string ioctlDir = SHARE_PATH_HEAD + std::to_string(userId) + LOWER_SHARE_PATH_MID; - UniqueFd dirFd(open(ioctlDir.c_str(), O_RDONLY)); - if (dirFd < 0) { - LOGE("Open share path failed with %{public}d", errno); - return errno; - } - std::vector physicalPaths; - int getPhysicalPathRet = SandboxHelper::GetMediaSharePath(uriList, physicalPaths); - if (getPhysicalPathRet != E_OK) { - return -EINVAL; - } - std::string networkId = GetLocalNetworkId(); - std::string bundleName = MEDIA_BUNDLE_NAME; - for (size_t i = 0; i < uriList.size(); i++) { - Uri uri(uriList[i]); - LOGD("GetDfsUriFromLocal begin, uri: %{private}s", uriList[i].c_str()); - std::string distributedPath; - int ret = GetDistributedPath(uri, userId, distributedPath, bundleName, networkId); - if (ret != E_OK) { - return ret; - } - struct HmdfsDstInfo hdi; - InitHmdfsInfo(hdi, physicalPaths[i], distributedPath, bundleName); - ret = ioctl(dirFd, HMDFS_IOC_GET_DST_PATH, &hdi); - if (ret != E_OK && GetMergePathFd(hdi, dirFd, userId) != E_OK) { - return errno; - } - HmdfsUriInfo dfsUriInfo; - SetHmdfsUriInfo(dfsUriInfo, uri, hdi.size, networkId, bundleName); - uriToDfsUriMaps.insert({uriList[i], dfsUriInfo}); - } - LOGI("GetDfsUrisFromLocal successfully"); - return E_OK; -} - -int32_t RemoteFileShare::GetDfsUrisFromLocal(const std::vector &uriList, - const int32_t &userId, - std::unordered_map &uriToDfsUriMaps) -{ - std::vector otherUriList; - std::vector mediaUriList; - int ret = UriCategoryByType(uriList, mediaUriList, otherUriList); - if (ret == E_OK && mediaUriList.size() != E_OK) { - ret = GetMediaDfsUrisFromLocal(mediaUriList, userId, uriToDfsUriMaps); - } - if (ret != E_OK) { - return ret; - } - std::string ioctlDir = SHARE_PATH_HEAD + std::to_string(userId) + LOWER_SHARE_PATH_MID; - UniqueFd dirFd(open(ioctlDir.c_str(), O_RDONLY)); - if (dirFd < 0) { - LOGE("Open share path failed with %{public}d", errno); - return errno; - } - std::string networkId = GetLocalNetworkId(); - for (const auto &uriStr : otherUriList) { - Uri uri(uriStr); - std::string bundleName = uri.GetAuthority(); - LOGD("GetDfsUriFromLocal begin, uri: %{private}s", uriStr.c_str()); - std::string physicalPath = GetPhysicalPath(uri, std::to_string(userId)); - if (physicalPath == "") { - LOGE("Failed to get physical path"); - return -EINVAL; - } - if (bundleName == FILE_MANAGER_AUTHORITY) { - HmdfsUriInfo dfsUriInfo; - (void)SetPublicDirHmdfsInfo(physicalPath, uriStr, dfsUriInfo, networkId); - uriToDfsUriMaps.insert({uriStr, dfsUriInfo}); - continue; - } - - std::string distributedPath; - ret = GetDistributedPath(uri, userId, distributedPath, bundleName, networkId); - if (ret != E_OK) { - return ret; - } - struct HmdfsDstInfo hdi; - InitHmdfsInfo(hdi, physicalPath, distributedPath, bundleName); - ret = ioctl(dirFd, HMDFS_IOC_GET_DST_PATH, &hdi); - if (ret != E_OK && GetMergePathFd(hdi, dirFd, userId) != E_OK) { - return errno; - } - HmdfsUriInfo dfsUriInfo; - SetHmdfsUriInfo(dfsUriInfo, uri, hdi.size, networkId, bundleName); - uriToDfsUriMaps.insert({uriStr, dfsUriInfo}); - } - LOGI("GetDfsUrisFromLocal successfully"); - return E_OK; -} - static sptr GetStorageManager() { auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); diff --git a/test/unittest/remote_file_share/remote_file_share_test.cpp b/test/unittest/remote_file_share/remote_file_share_test.cpp index 328209ba8..a8db0405b 100644 --- a/test/unittest/remote_file_share/remote_file_share_test.cpp +++ b/test/unittest/remote_file_share/remote_file_share_test.cpp @@ -179,409 +179,6 @@ namespace { GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0005"; } - /** - * @tc.name: remote_file_share_test_0005 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0005, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0005"; - const string dirPath = "/data/app/el2/100/base/com.demo.a/"; - const string uriStr = "file://com.demo.a/data/storage/el2/base/remote_file_share_test.txt"; - const string fileStr = "/data/app/el2/100/base/com.demo.a/remote_file_share_test.txt"; - const int userId = 100; - - int ret = mkdir(dirPath.c_str(), S_IRWXU | S_IRWXG | S_IXOTH); - ASSERT_TRUE((ret != -1) || (ret == -1 && errno == EEXIST)) << "RemoteFileShareTest mkdir failed! " << errno; - - int fd = open(fileStr.c_str(), O_RDWR | O_CREAT); - ASSERT_TRUE(fd != -1) << "Failed to open file in RemoteFileShareTest! " << errno; - close(fd); - - HmdfsUriInfo hui; - ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, E_OK); - - ret = unlink(fileStr.c_str()); - ASSERT_TRUE(ret != -1) << "Failed to delete file in RemoteFileShareTest! " << errno; - - ret = rmdir(dirPath.c_str()); - ASSERT_TRUE(ret != -1) << "RemoteFileShareTest rmdir failed! " << errno; - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0005"; - } - - /** - * @tc.name: remote_file_share_test_0006 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for FAILURE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0006, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0006"; - const string uriStr = ""; - const int userId = 100; - HmdfsUriInfo hui; - int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, -EINVAL); - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_EQ(ret, -EINVAL); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0006"; - } - - /** - * @tc.name: remote_file_share_test_0007 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for FAILURE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0007, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0007"; - const string uriStr = "file://com.demo.a/../data/storage/el2/base/remote_file_share_test.txt"; - const int userId = 100; - HmdfsUriInfo hui; - int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, -EINVAL); - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_EQ(ret, -EINVAL); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0007"; - } - - /** - * @tc.name: remote_file_share_test_0008 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for FAILURE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0008, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0008"; - const string uriStr = "file://com.demo.a/../data/storage/el2/base/remote_file_share_test.txt"; - const int userId = 100; - HmdfsUriInfo hui; - int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, -EINVAL); - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_EQ(ret, -EINVAL); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0008"; - } - - /** - * @tc.name: remote_file_share_test_0009 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for FAILURE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0009, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0009"; - const string uriStr = "file://com.demo.a/data/storage/el3/base/remote_file_share_test.txt"; - const int userId = 100; - HmdfsUriInfo hui; - int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, -EINVAL); - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_EQ(ret, -EINVAL); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0009"; - } - - /** - * @tc.name: remote_file_share_test_0010 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for FAILURE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0010, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0010"; - const string uriStr = "file://com.demo.a/data/storage/el2/base/notExistFile.txt"; - const int userId = 100; - HmdfsUriInfo hui; - int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_NE(ret, E_OK); - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_NE(ret, E_OK); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0010"; - } - - /** - * @tc.name: remote_file_share_test_0011 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for SUCCESS. - * the file name is chinese which has been encoded - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0011, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0011"; - const string dirPath = "/data/app/el2/100/base/com.demo.a/"; - const string uriStr = "file://com.demo.a/data/storage/el2/base/" - "%E5%85%B1%20%E4%BA%AB%20%E6%96%87%20%E4%BB%B6%20%E6%B5%8B%20%E8%AF%95.txt"; - const string fileStr = "/data/app/el2/100/base/com.demo.a/共 享 文 件 测 试.txt"; - const int userId = 100; - - int ret = mkdir(dirPath.c_str(), S_IRWXU | S_IRWXG | S_IXOTH); - ASSERT_TRUE((ret != -1) || (ret == -1 && errno == EEXIST)) << "RemoteFileShareTest mkdir failed! " << errno; - - int fd = open(fileStr.c_str(), O_RDWR | O_CREAT); - ASSERT_TRUE(fd != -1) << "RemoteFileShareTest open file failed! " << errno; - close(fd); - - HmdfsUriInfo hui; - ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, E_OK); - ret = unlink(fileStr.c_str()); - ASSERT_TRUE(ret != -1) << "RemoteFileShareTest delete file failed! " << errno; - - ret = rmdir(dirPath.c_str()); - ASSERT_TRUE(ret != -1) << "RemoteFileShareTest rmdir failed! " << errno; - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_NE(ret, E_OK); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0011"; - } - - /** - * @tc.name: Remote_file_share_GetDfsUriFromLocal_0012 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for FAILURE. - * the file name is chinese which has been encoded - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0012, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0012"; - string uriStr = "datashare://media/Photo/12/IMG_12345_0011/test.jpg"; - const int userId = 100; - - HmdfsUriInfo hui; - auto ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, -EINVAL); - - uriStr = "datashare://media/Photo/12/IMG_12345_0011/test.jpg/others"; - ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, -EINVAL); - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0012"; - } - - /** - * @tc.name: Remote_file_share_GetDfsUriFromLocal_0013 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for SUCCESS. - * the file name is chinese which has been encoded - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0013, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0013"; - const string uriStr = "file://media/Photo/12/IMG_12345_0011/test.jpg"; - const int userId = 100; - - HmdfsUriInfo hui; - auto ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_NE(ret, 0); - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0013"; - } - - /** - * @tc.name: Remote_file_share_GetDfsUriFromLocal_0014 - * @tc.desc: Test function of GetDfsUriFromLocal() interface for SUCCESS. - * the file name is chinese which has been encoded - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0014, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0014"; - const string uriStr = "file://docs/storage/Users/currentUser/Documents/1.txt"; - const int userId = 100; - - HmdfsUriInfo hui; - auto ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, E_OK); - EXPECT_EQ(hui.fileSize, 0); - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0014"; - } - - /** - * @tc.name: remote_file_share_GetDfsUriFromLocal_0015 - * @tc.desc: Test function of GetDfsUrisFromLocal() interface. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0015, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0015"; - const string uriStr = "file://media/Photo/test/IMG_12345_0011/test.jpg"; - const int userId = USER_ID; - HmdfsUriInfo hui; - int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_NE(ret, E_OK); - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_NE(ret, E_OK); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0015"; - } - - /** - * @tc.name: remote_file_share_GetDfsUriFromLocal_0016 - * @tc.desc: Test function of GetDfsUrisFromLocal() interface. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0016, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0016"; - const string uriStr = "file://docs/storage/Users/currentUser/Documents/1.txt"; - const int userId = USER_ID; - HmdfsUriInfo hui; - int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, E_OK); - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_EQ(ret, E_OK); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0016"; - } - - /** - * @tc.name: remote_file_share_GetDfsUriFromLocal_0017 - * @tc.desc: Test function of GetDfsUrisFromLocal() interface. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0017, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0017"; - const string uriStr = "file://docs/storage/Users/currentUser/Documents/1.txt"; - const string uriStr1 = "file://media/Photo/test/IMG_12345_0011/test.jpg"; - const int userId = USER_ID; - HmdfsUriInfo hui; - int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); - EXPECT_EQ(ret, E_OK); - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - uriList.push_back(uriStr1); - ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_EQ(ret, -EINVAL); - - GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; - GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0017"; - } - - /** - * @tc.name: remote_file_share_GetDfsUriFromLocal_0018 - * @tc.desc: Test function of GetDfsUrisFromLocal() interface. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: I7KDF7 - */ - HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0018, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0018"; - const string uriStr = "file://media/Photo/test/IMG_12345_0011/test.jpg"; - const string uriStr1 = "file://media/Photo/test/IMG_12345_0012/test1.jpg"; - const string uriStr2 = "file://media/Photo/test/IMG_12345_0013/test1.jpg"; - const int userId = USER_ID; - - vector uriList; - unordered_map uriToDfsUriMaps; - uriList.push_back(uriStr); - uriList.push_back(uriStr1); - uriList.push_back(uriStr2); - int ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); - EXPECT_EQ(ret, -EINVAL); - - GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0018"; - } - /** * @tc.name: remote_file_share_test_0012 * @tc.desc: Test function of TransRemoteUriToLocal() interface for SUCCESS. -- Gitee From 1b233a17215c2ec12459c96c4267cb83cd3840aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E4=BD=B3=E7=82=9C?= Date: Thu, 11 Sep 2025 10:40:26 +0800 Subject: [PATCH 2/2] delete ioctl get path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 石佳炜 --- .../remote_file_share/src/remote_file_share.cpp | 13 ------------- 1 file changed, 13 deletions(-) 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 9d8de33b3..e9f3c02b0 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 @@ -409,19 +409,6 @@ static std::string GetLocalNetworkId() return networkId; } -static void SetHmdfsUriInfo(struct HmdfsUriInfo &hui, - Uri &uri, - uint64_t fileSize, - const std::string &networkId, - const std::string &bundleName) -{ - hui.uriStr = FILE_SCHEME + "://" + bundleName + DISTRIBUTED_DIR_PATH + REMOTE_SHARE_PATH_DIR + BACKSLASH + - networkId + uri.GetPath() + NETWORK_PARA + networkId; - - hui.fileSize = fileSize; - return; -} - static int32_t SetFileSize(const std::string &physicalPath, struct HmdfsUriInfo &hui) { struct stat buf = {}; -- Gitee