From bac59d244eb979d9d54b31cac9cf20e74ae68d13 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 6 Jul 2023 06:57:13 +0000 Subject: [PATCH 1/3] remote_file_share Signed-off-by: liuzerun --- BUILD.gn | 2 +- bundle.json | 2 +- interfaces/common/include/common_func.h | 33 ++ interfaces/common/include/log.h | 36 ++ interfaces/common/src/common_func.cpp | 113 ++++++ .../innerkits/native/file_share/BUILD.gn | 7 +- .../native/file_share/src/file_share.cpp | 96 +----- .../native/remote_file_share/BUILD.gn | 51 +++ .../include/remote_file_share.h | 45 +++ .../include/remote_file_share_log.h | 35 ++ .../src/remote_file_share.cpp | 326 ++++++++++++++++++ interfaces/kits/js/BUILD.gn | 4 +- test/unittest/remote_file_share/BUILD.gn | 2 +- 13 files changed, 658 insertions(+), 94 deletions(-) create mode 100644 interfaces/common/include/common_func.h create mode 100644 interfaces/common/include/log.h create mode 100644 interfaces/common/src/common_func.cpp create mode 100644 interfaces/innerkits/native/remote_file_share/BUILD.gn create mode 100644 interfaces/innerkits/native/remote_file_share/include/remote_file_share.h create mode 100644 interfaces/innerkits/native/remote_file_share/include/remote_file_share_log.h create mode 100644 interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp diff --git a/BUILD.gn b/BUILD.gn index c70a22860..8c984a11f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -16,7 +16,7 @@ import("//build/ohos.gni") group("libremotefileshare") { deps = [ "interfaces/innerkits/native/file_share:fileshare_native", - "interfaces/innerkits/remote_file_share/native:remote_file_share_native", + "interfaces/innerkits/native/remote_file_share:remote_file_share_native", "interfaces/kits/js:remotefileshare", ] } diff --git a/bundle.json b/bundle.json index 58a13df90..c6e7d1fdf 100644 --- a/bundle.json +++ b/bundle.json @@ -74,7 +74,7 @@ } }, { - "name": "//foundation/filemanagement/app_file_service/interfaces/innerkits/remote_file_share/native:remote_file_share_native", + "name": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native/remote_file_share:remote_file_share_native", "header": { "header_files": [ "remote_file_share.h" diff --git a/interfaces/common/include/common_func.h b/interfaces/common/include/common_func.h new file mode 100644 index 000000000..d2eeed318 --- /dev/null +++ b/interfaces/common/include/common_func.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APP_FILE_SERVICE_COMMON_FUNC +#define APP_FILE_SERVICE_COMMON_FUNC + +#include + +namespace OHOS { +namespace AppFileService { +class CommonFunc +{ +public: + static bool CheckValidPath(const std::string &filePath); + static int32_t GetPhysicalPath(const std::string &fileUri, const std::string &userId, + std::string &physicalPath); +}; +} +} + +#endif \ No newline at end of file diff --git a/interfaces/common/include/log.h b/interfaces/common/include/log.h new file mode 100644 index 000000000..9d80fbe8c --- /dev/null +++ b/interfaces/common/include/log.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef LOG_H +#define LOG_H +#include "hilog/log.h" + +namespace OHOS { +namespace AppFileService { +const unsigned int APP_LOG_DOMAIN = 0xD004313; +const char APP_LOG_TAG[] = "AppFileService"; +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, APP_LOG_DOMAIN, APP_LOG_TAG }; + +#define PRINT_LOG(Level, fmt, ...) \ + OHOS::HiviewDFX::HiLog::Level(OHOS::AppFileService::LOG_LABEL, "[%{public}s:%{public}d] " fmt, \ + __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#define LOGI(fmt, ...) PRINT_LOG(Info, fmt, ##__VA_ARGS__) +#define LOGW(fmt, ...) PRINT_LOG(Warn, fmt, ##__VA_ARGS__) +#define LOGE(fmt, ...) PRINT_LOG(Error, fmt, ##__VA_ARGS__) +#define LOGF(fmt, ...) PRINT_LOG(Fatal, fmt, ##__VA_ARGS__) +} // namespace AppFileService +} // namespace OHOS + +#endif // LOG_H \ No newline at end of file diff --git a/interfaces/common/src/common_func.cpp b/interfaces/common/src/common_func.cpp new file mode 100644 index 000000000..9f3033782 --- /dev/null +++ b/interfaces/common/src/common_func.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common_func.h" + +#include +#include "uri.h" + +using namespace std; + +namespace OHOS { +namespace AppFileService { +const string PACKAGE_NAME_FLAG = ""; +const string CURRENT_USER_ID_FLAG = ""; +const vector SANDBOX_PATH = { + "/data/storage/el1/bundle", + "/data/storage/el2/base", + "/data/storage/el1/database", + "/data/storage/el2/database", + "/data/storage/el1/base", + "/data/storage/ark-cache", + "/data/storage/ark-profile", + "/data/storage/el2/distributedfiles", + "/mnt/data/fuse", + "/storage/local/Documents" +}; + +const vector LOWER_PATH = { + "/data/app/el1/bundle/public/", + "/data/app/el2//base/", + "/data/app/el1//database/", + "/data/app/el2//database/", + "/data/app/el1//base/", + "/data/local/ark-cache/", + "/data/local/ark-profile//", + "/mnt/hmdfs//account/merge_view/data/", + "/mnt/sandbox//mnt/data/fuse", + "/mnt/hmdfs//account/merge_view/files/Documents" +}; + +static string GetLowerPath(string &lowerPathHead, const string &lowerPathTail, + const string &userId, const string &bundleName) +{ + if (lowerPathHead.find(CURRENT_USER_ID_FLAG) != string::npos) { + lowerPathHead = lowerPathHead.replace(lowerPathHead.find(CURRENT_USER_ID_FLAG), + CURRENT_USER_ID_FLAG.length(), userId); + } + + if (lowerPathHead.find(PACKAGE_NAME_FLAG) != string::npos) { + lowerPathHead = lowerPathHead.replace(lowerPathHead.find(PACKAGE_NAME_FLAG), + PACKAGE_NAME_FLAG.length(), bundleName); + } + + return lowerPathHead + lowerPathTail; +} + +int32_t CommonFunc::GetPhysicalPath(const std::string &fileUri, const std::string &userId, + std::string &physicalPath) +{ + Uri uri(fileUri); + string bundleName = uri.GetAuthority(); + string sandboxPath = uri.GetPath(); + string lowerPathTail = ""; + string lowerPathHead = ""; + + for (size_t i = 0; i < SANDBOX_PATH.size(); i++) { + if (sandboxPath.length() >= SANDBOX_PATH[i].length()) { + string sandboxPathTemp = sandboxPath.substr(0, SANDBOX_PATH[i].length()); + if (sandboxPathTemp == SANDBOX_PATH[i]) { + lowerPathHead = LOWER_PATH[i]; + lowerPathTail = sandboxPath.substr(SANDBOX_PATH[i].length()); + break; + } + } + } + + if (lowerPathHead == "") { + return -EINVAL; + } else { + physicalPath = GetLowerPath(lowerPathHead, lowerPathTail, userId, bundleName); + return 0; + } +} + +bool CommonFunc::CheckValidPath(const std::string &filePath) +{ + if (filePath.empty() || filePath.size() >= PATH_MAX) { + return false; + } + + char realPath[PATH_MAX]{'\0'}; + if (realpath(filePath.c_str(), realPath) != nullptr && + strncmp(realPath, filePath.c_str(), filePath.size()) == 0) { + return true; + } else { + return false; + } +} +} // namespace AppFileService +} // namespace OHOS + diff --git a/interfaces/innerkits/native/file_share/BUILD.gn b/interfaces/innerkits/native/file_share/BUILD.gn index 6f9b24ff6..1a9b0995e 100644 --- a/interfaces/innerkits/native/file_share/BUILD.gn +++ b/interfaces/innerkits/native/file_share/BUILD.gn @@ -17,12 +17,15 @@ config("file_share_config") { visibility = [ ":*" ] include_dirs = [ "include", - "../common", + "../../../common/include", ] } ohos_shared_library("fileshare_native") { - sources = [ "src/file_share.cpp" ] + sources = [ + "src/file_share.cpp", + "../../../common/src/common_func.cpp", + ] public_configs = [ ":file_share_config" ] diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 3ca42a513..cf7794151 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -23,6 +23,7 @@ #include #include "accesstoken_kit.h" +#include "common_func.h" #include "hap_token_info.h" #include "log.h" #include "uri.h" @@ -41,27 +42,6 @@ struct FileShareInfo { SHARE_FILE_TYPE type_; }; -static void UpdateBundleNameForDlp(const string &providerPath, string &bundleName, const string &providerBundleName) -{ - if (providerBundleName == DLP_MANAGER_BUNDLE_NAME) { - size_t lastPos = providerPath.find_last_of("/"); - if (lastPos == string::npos) { - return; - } - string subStr = providerPath.substr(lastPos); - size_t firstPos = subStr.find_first_of("_"); - if (firstPos == string::npos) { - return; - } - subStr = subStr.substr(firstPos + 1); - size_t secondPos = subStr.find_first_of("_"); - if (secondPos == string::npos) { - return; - } - bundleName += "_" + subStr.substr(0, secondPos); - } -} - static int32_t GetTargetInfo(uint32_t tokenId, string &bundleName, string ¤tUid) { Security::AccessToken::HapTokenInfo hapInfo; @@ -72,6 +52,11 @@ static int32_t GetTargetInfo(uint32_t tokenId, string &bundleName, string &curre } bundleName = hapInfo.bundleName; currentUid = to_string(hapInfo.userID); + + int index = hapInfo.instIndex; + if (index != 0) { + bundleName += "_" + to_string(index); + } return 0; } @@ -100,55 +85,6 @@ static bool IsExistFile(const string &path) return S_ISREG(buf.st_mode); } -static int32_t GetLowerPath(string &lowerPathHead, const string &lowerPathTail, FileShareInfo &info) -{ - if (lowerPathHead.empty()) { - return -EINVAL; - } - - if (lowerPathHead.find(CURRENT_USER_ID_FLAG) != string::npos) { - lowerPathHead = lowerPathHead.replace(lowerPathHead.find(CURRENT_USER_ID_FLAG), - CURRENT_USER_ID_FLAG.length(), info.currentUid_); - } - - if (lowerPathHead.find(PACKAGE_NAME_FLAG) != string::npos) { - lowerPathHead = lowerPathHead.replace(lowerPathHead.find(PACKAGE_NAME_FLAG), - PACKAGE_NAME_FLAG.length(), info.providerBundleName_); - } - - info.providerLowerPath_ = lowerPathHead + lowerPathTail; - return 0; -} - -static int32_t GetProviderPath(const string &uriStr, FileShareInfo &info) -{ - Uri uri(uriStr); - string pathInProvider = uri.GetPath(); - UpdateBundleNameForDlp(pathInProvider, info.targetBundleName_, info.providerBundleName_); - size_t num = SANDBOX_PATH.size(); - string lowerPathTail = "", lowerPathHead = ""; - - for (size_t i = 0; i < num; i++) { - if (pathInProvider.length() >= SANDBOX_PATH[i].length()) { - string sandboxPathTemp = pathInProvider.substr(0, SANDBOX_PATH[i].length()); - if (sandboxPathTemp == SANDBOX_PATH[i]) { - lowerPathHead = LOWER_PATH[i]; - lowerPathTail = pathInProvider.substr(SANDBOX_PATH[i].length()); - break; - } - } - } - - int32_t ret = GetLowerPath(lowerPathHead, lowerPathTail, info); - if (ret != 0) { - LOGE("Get lower path failed with %{public}d", ret); - return ret; - } - - info.providerSandboxPath_ = pathInProvider; - return 0; -} - static void GetSharePath(FileShareInfo &info, uint32_t flag) { string shareRPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH +info.targetBundleName_ + @@ -188,7 +124,8 @@ static int32_t GetFileShareInfo(const string &uri, uint32_t tokenId, uint32_t fl } GetProviderBundleName(uri, info.providerBundleName_); - ret = GetProviderPath(uri, info); + + ret = CommonFunc::GetPhysicalPath(uri, info.currentUid_, info.providerLowerPath_); if (ret != 0) { LOGE("Failed to get lower path %{public}d", ret); return ret; @@ -226,24 +163,9 @@ static bool MakeDir(const string &path) return true; } -static bool CheckValidPath(const string &filePath) -{ - if (filePath.size() >= PATH_MAX) { - return false; - } - - char realPath[PATH_MAX]{'\0'}; - if (realpath(filePath.c_str(), realPath) != nullptr && - strncmp(realPath, filePath.c_str(), filePath.size()) == 0) { - return true; - } else { - return false; - } -} - static int32_t PreparePreShareDir(FileShareInfo &info) { - if (!CheckValidPath(info.providerLowerPath_)) { + if (CommonFunc::CheckValidPath(info.providerLowerPath_)) { LOGE("Invalid share path with %{private}s", info.providerLowerPath_.c_str()); return -EINVAL; } diff --git a/interfaces/innerkits/native/remote_file_share/BUILD.gn b/interfaces/innerkits/native/remote_file_share/BUILD.gn new file mode 100644 index 000000000..051ab9355 --- /dev/null +++ b/interfaces/innerkits/native/remote_file_share/BUILD.gn @@ -0,0 +1,51 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") +config("remote_file_share_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "${utils_system_safwk_path}/native/include", + "${path_base}/include", + "../../../common/include", + ".", + ] +} + +ohos_shared_library("remote_file_share_native") { + sources = [ + "./src/remote_file_share.cpp", + "../../../common/src/common_func.cpp", + ] + + public_configs = [ ":remote_file_share_config" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + + defines = [ + "REMOTE_SHARE_FILE_LOG_TAG=\"RemoteFileShare\"", + "LOG_DOMAIN=0xD004312", + ] + + innerapi_tags = [ "platformsdk_indirect" ] + part_name = "app_file_service" + subsystem_name = "filemanagement" +} 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 new file mode 100644 index 000000000..dff1049d9 --- /dev/null +++ b/interfaces/innerkits/native/remote_file_share/include/remote_file_share.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef REMOTE_FILE_SHARE_H +#define REMOTE_FILE_SHARE_H + +#include + +namespace OHOS { +namespace AppFileService { +namespace ModuleRemoteFileShare { +namespace { + const std::string SHARE_ALL_DEVICE = "0"; +} + +struct HmdfsUriInfo { + std::string uriStr; + size_t fileSize; +}; + +class RemoteFileShare { +public: + RemoteFileShare() {} + static int CreateSharePath(const int &fd, std::string &sharePath, + const int &userId, const std::string &deviceId = SHARE_ALL_DEVICE); + static int GetDfsUriFromLocal(const std::string &uriStr, const int &userId, struct HmdfsUriInfo &hui); + ~RemoteFileShare() {} +}; +} // namespace ModuleRemoteFileShare +} // namespace AppFileService +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native/remote_file_share/include/remote_file_share_log.h b/interfaces/innerkits/native/remote_file_share/include/remote_file_share_log.h new file mode 100644 index 000000000..510e9c751 --- /dev/null +++ b/interfaces/innerkits/native/remote_file_share/include/remote_file_share_log.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef REMOTE_FILE_SHARE_LOG_H +#define REMOTE_FILE_SHARE_LOG_H + +#include "hilog/log.h" + +namespace OHOS { +namespace AppFileService { +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_DOMAIN, REMOTE_SHARE_FILE_LOG_TAG}; + +#define PRINT_LOG(Level, fmt, ...) \ + OHOS::HiviewDFX::HiLog::Level(OHOS::AppFileService::LOG_LABEL, "[%{public}s:%{public}d] " fmt, \ + __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#define LOGI(fmt, ...) PRINT_LOG(Info, fmt, ##__VA_ARGS__) +#define LOGW(fmt, ...) PRINT_LOG(Warn, fmt, ##__VA_ARGS__) +#define LOGE(fmt, ...) PRINT_LOG(Error, fmt, ##__VA_ARGS__) +#define LOGF(fmt, ...) PRINT_LOG(Fatal, fmt, ##__VA_ARGS__) +} // namespace AppFileService +} // namespace OHOS + +#endif // REMOTE_FILE_SHARE_LOG_H \ No newline at end of file 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 new file mode 100644 index 000000000..900549635 --- /dev/null +++ b/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp @@ -0,0 +1,326 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "remote_file_share.h" +#include "remote_file_share_log.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "directory_ex.h" +#include "securec.h" +#include "common_func.h" +#include "uri.h" + +namespace OHOS { +namespace AppFileService { +namespace ModuleRemoteFileShare { +namespace { + const int HMDFS_CID_SIZE = 64; + const int USER_ID_INIT = 100; + const int BUNDLENAME_BEGIN = 7; + const unsigned HMDFS_IOC = 0xf2; + const std::string URI_HEAD = "file://"; + const std::string URI_MID = "/data/storage/el2/distributedfiles"; + const std::string DST_PATH_HEAD = "/data/service/el2/"; + const std::string DST_PATH_MID = "/hmdfs/account/data/"; + const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; + const std::string SHAER_PATH_MID = "/account/merge_view/services/"; + const std::string SHAER_FILE_PATH = "/account/merge_view/data/remote_share.txt"; + const std::string LOWER_SHARE_PATH_HEAD = "/mnt/hmdfs/"; + const std::string LOWER_SHARE_PATH_MID = "/account/device_view/local/services/"; +} + +#define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, struct HmdfsShareControl) +#define HMDFS_IOC_GET_DRAG_PATH _IOR(HMDFS_IOC, 3, unsigned int) + +struct HmdfsShareControl { + int fd; + char deviceId[HMDFS_CID_SIZE]; +}; + +struct HmdfsDragInfo { + unsigned long localLen; + unsigned long localPath; + unsigned long cloudLen; + unsigned long cloudPath; +}; + +static std::string GetProcessName() +{ + char pthreadName[PATH_MAX]; + int ret = pthread_getname_np(pthread_self(), pthreadName, sizeof(pthreadName)); + if (ret != 0) { + LOGE("RemoteFileShare::GetProcessName, pthread_getname_np failed with %{public}d", errno); + return ""; + } + std::string pthreadNameStr = pthreadName; + LOGI("RemoteFileShare::GetProcessName, thread name is %{public}s", pthreadNameStr.c_str()); + return pthreadNameStr; +} + +static std::string GetFileName(const int &fd) +{ + char buf[PATH_MAX] = {'\0'}; + char filePath[PATH_MAX] = {'\0'}; + + int ret = snprintf_s(buf, sizeof(buf), sizeof(buf), "/proc/self/fd/%d", fd); + if (ret < 0) { + LOGE("RemoteFileShare::GetFileName, snprintf failed with %{public}d", errno); + return ""; + } + + ret = readlink(buf, filePath, PATH_MAX); + if (ret < 0 || ret >= PATH_MAX) { + LOGE("RemoteFileShare::GetFileName, readlink failed with %{public}d", errno); + return ""; + } + + std::string fileName = filePath; + std::size_t firstSlash = fileName.rfind("/"); + if (firstSlash == fileName.npos) { + LOGE("RemoteFileShare::GetFileName, get error path with %{public}s", fileName.c_str()); + return ""; + } + fileName = fileName.substr(firstSlash + 1, fileName.size() - firstSlash); + return fileName; +} + +static int CreateShareDir(const std::string &path) +{ + if (access(path.c_str(), F_OK) != 0) { + int ret = mkdir(path.c_str(), S_IRWXU); + if (ret != 0) { + LOGE("RemoteFileShare::CreateShareDir, make dir failed with %{public}d", errno); + return errno; + } + } + return 0; +} + +static std::string GetSharePath(const int &userId, const std::string &packageName) +{ + return SHAER_PATH_HEAD + std::to_string(userId) + SHAER_PATH_MID + packageName; +} + +static std::string GetLowerSharePath(const int &userId, const std::string &packageName) +{ + return LOWER_SHARE_PATH_HEAD + std::to_string(userId) + LOWER_SHARE_PATH_MID + packageName; +} + +static bool DeleteShareDir(const std::string &PACKAGE_PATH, const std::string &SHARE_PATH) +{ + bool result = true; + if (access(SHARE_PATH.c_str(), F_OK) == 0) { + int ret = rmdir(SHARE_PATH.c_str()); + if (ret != 0) { + LOGE("RemoteFileShare::DeleteShareDir, delete dir failed with %{public}d", errno); + result = false; + } else { + LOGI("RemoteFileShare::DeleteShareDir, delete %{public}s path successfully", SHARE_PATH.c_str()); + } + } + if (access(PACKAGE_PATH.c_str(), F_OK) == 0) { + int ret = rmdir(PACKAGE_PATH.c_str()); + if (ret != 0) { + LOGE("RemoteFileShare::DeleteShareDir, delete dir failed with %{public}d", errno); + result = false; + } else { + LOGI("RemoteFileShare::DeleteShareDir, delete %{public}s path successfully", PACKAGE_PATH.c_str()); + } + } + return result; +} + +static int CreateShareFile(struct HmdfsShareControl &shareControl, const char* file, + const std::string &deviceId) +{ + int32_t dirFd = open(file, O_RDONLY); + if (dirFd < 0) { + LOGE("RemoteFileShare::CreateShareFile, open share path failed with %{public}d", errno); + return errno; + } + + memset_s(shareControl.deviceId, HMDFS_CID_SIZE, '\0', HMDFS_CID_SIZE); + if (memcpy_s(shareControl.deviceId, HMDFS_CID_SIZE, deviceId.c_str(), deviceId.size()) != 0) { + LOGE("RemoteFileShare::CreateShareFile, memcpy_s failed with %{public}d", errno); + close(dirFd); + return errno; + } + + if (ioctl(dirFd, HMDFS_IOC_SET_SHARE_PATH, &shareControl) < 0) { + LOGE("RemoteFileShare::CreateShareFile, ioctl failed with %{public}d", errno); + close(dirFd); + return errno; + } + close(dirFd); + return 0; +} + +static int CheckInputValidity(const int &fd, const int &userId, const std::string &deviceId) +{ + return (fd < 0) || (userId < USER_ID_INIT) || (deviceId != SHARE_ALL_DEVICE && + deviceId.size() != HMDFS_CID_SIZE); +} + +static int GetDistributedPath(const std::string &bundleName, const int &userId, + const std::string &physicalPath, std::string &distributedPath) +{ + distributedPath = DST_PATH_HEAD + std::to_string(userId) + + DST_PATH_MID + bundleName + "/" + physicalPath; + if (int(distributedPath.size()) >= PATH_MAX) + return -EINVAL; + else + return 0; +} + +size_t GetFileSize(const std::string &fileName) +{ + size_t filesize; + struct stat statbuf; + + if (fileName.empty()) { + return 0; + } + stat(fileName.c_str(), &statbuf); + filesize = statbuf.st_size; + return filesize; +} + +int RemoteFileShare::CreateSharePath(const int &fd, std::string &sharePath, + const int &userId, const std::string &deviceId) +{ + struct HmdfsShareControl shareControl; + shareControl.fd = fd; + + if (CheckInputValidity(fd, userId, deviceId) != 0) { + LOGE("RemoteFileShare::CreateSharePath, invalid argument with %{public}d", EINVAL); + return EINVAL; + } + + const std::string processName = GetProcessName(); + if (processName == "") { + LOGE("RemoteFileShare::CreateSharePath, GetProcessName failed with %{public}d", errno); + return errno; + } + + const std::string PACKAGE_PATH = GetLowerSharePath(userId, processName); + const std::string LOWER_SHARE_PATH = PACKAGE_PATH + "/.share"; + if (CreateShareDir(PACKAGE_PATH) != 0) + return errno; + if (CreateShareDir(LOWER_SHARE_PATH) != 0) { + DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); + return errno; + } + + const std::string SHARE_PATH = GetSharePath(userId, processName) + "/.share"; + char realPath[PATH_MAX] = {'\0'}; + if (!realpath(SHARE_PATH.c_str(), realPath)) { + LOGE("RemoteFileShare::CreateSharePath, realpath failed with %{public}d", errno); + DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); + return errno; + } + + std::string file_name = GetFileName(shareControl.fd); + if (file_name == "") { + LOGE("RemoteFileShare::CreateSharePath, get error file name"); + DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); + return EBADF; + } + sharePath = SHARE_PATH + "/" + file_name; + + if (CreateShareFile(shareControl, realPath, deviceId) != 0) { + LOGE("RemoteFileShare::CreateSharePath, create share file failed with %{public}d", errno); + /* When the file is exist, we should not delete the dictionary */ + if (errno == EEXIST) { + return 0; + } + sharePath = ""; + DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); + return errno; + } + LOGI("RemoteFileShare::CreateSharePath, create %{public}s successfully", sharePath.c_str()); + return 0; +} + +int RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, + const int &userId, struct HmdfsUriInfo &hui) +{ + int ret; + const char *physicalChar; + const char *distributedChar; + Uri uri(uriStr); + std::string bundleName = uri.GetAuthority(); + std::string physicalPath; + std::string distributedPath; + std::string usingFile = SHAER_PATH_HEAD + + std::to_string(userId) + + SHAER_FILE_PATH; + struct HmdfsDragInfo hdi; + ret = AppFileService::CommonFunc::GetPhysicalPath(uriStr, + std::to_string(userId), physicalPath); + if (ret != 0) { + LOGE("Failed to get lower path %{public}d", ret); + return ret; + } + if (!CommonFunc::CheckValidPath(physicalPath)) { + LOGE("Illegal path"); + return -EINVAL; + } + + ret = GetDistributedPath(bundleName, userId, physicalPath, distributedPath); + if (ret != 0) { + LOGE("Path is too long %{public}d", ret); + return ret; + } + + ret = OHOS::ForceCreateDirectory(distributedPath.substr(0, + distributedPath.find_last_of('/'))); + if (ret == 1) { + LOGE("Open distributed path failed"); + return ret; + } + + int32_t hmdfsDevFd = open(usingFile.c_str(), O_RDONLY); + if (hmdfsDevFd < 0) { + LOGE("RemoteFileShare::CreateShareFile, open share path failed with %{public}d", errno); + return errno; + } + + physicalChar = physicalPath.c_str(); + distributedChar = distributedPath.c_str(); + hdi.localLen = physicalPath.size() + 1; + hdi.localPath = (unsigned long)(physicalChar); + hdi.cloudLen = distributedPath.size() + 1; + hdi.cloudPath = (unsigned long)(distributedChar); + + ret = ioctl(hmdfsDevFd, HMDFS_IOC_GET_DRAG_PATH, hdi); + if (ret != 0) { + LOGE("Ioctl failed %{public}d", ret); + return ret; + } + hui.fileSize = GetFileSize(physicalPath); + hui.uriStr = URI_HEAD + bundleName + URI_MID + physicalPath; + return 0; + +} +} // namespace ModuleRemoteFileShare +} // namespace AppFileService +} // namespace OHOS diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 2c2cdb565..acc027080 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -39,7 +39,7 @@ ohos_shared_library("remotefileshare") { ohos_shared_library("fileshare") { include_dirs = [ ".", - "common", + "../../common/include", ] sources = [ @@ -71,7 +71,7 @@ ohos_shared_library("fileshare") { ohos_shared_library("fileuri") { include_dirs = [ ".", - "common", + "../../common/include", ] sources = [ diff --git a/test/unittest/remote_file_share/BUILD.gn b/test/unittest/remote_file_share/BUILD.gn index 8af8d3df7..56084b209 100644 --- a/test/unittest/remote_file_share/BUILD.gn +++ b/test/unittest/remote_file_share/BUILD.gn @@ -30,7 +30,7 @@ ohos_unittest("remote_file_share_test") { ] deps = [ - "../../../interfaces/innerkits/remote_file_share/native:remote_file_share_native", + "../../../interfaces/innerkits/native/remote_file_share:remote_file_share_native", "//third_party/googletest:gtest_main", ] } -- Gitee From 9df749baf1e10428b25868ca5c859e55df07b680 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 6 Jul 2023 07:09:39 +0000 Subject: [PATCH 2/3] remote_file_Share Signed-off-by: liuzerun --- .../src/remote_file_share.cpp | 223 ------------------ 1 file changed, 223 deletions(-) delete mode 100644 services/remote_file_share/src/remote_file_share.cpp diff --git a/services/remote_file_share/src/remote_file_share.cpp b/services/remote_file_share/src/remote_file_share.cpp deleted file mode 100644 index 865a69415..000000000 --- a/services/remote_file_share/src/remote_file_share.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "remote_file_share.h" -#include "remote_file_share_log.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "securec.h" - -namespace OHOS { -namespace AppFileService { -namespace ModuleRemoteFileShare { -namespace { - const int HMDFS_CID_SIZE = 64; - const int USER_ID_INIT = 100; - const unsigned HMDFS_IOC = 0xf2; - const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; - const std::string SHAER_PATH_MID = "/account/merge_view/services/"; - const std::string LOWER_SHARE_PATH_HEAD = "/mnt/hmdfs/"; - const std::string LOWER_SHARE_PATH_MID = "/account/device_view/local/services/"; -} - -#define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, struct HmdfsShareControl) - -struct HmdfsShareControl { - int fd; - char deviceId[HMDFS_CID_SIZE]; -}; - -static std::string GetProcessName() -{ - char pthreadName[PATH_MAX]; - int ret = pthread_getname_np(pthread_self(), pthreadName, sizeof(pthreadName)); - if (ret != 0) { - LOGE("RemoteFileShare::GetProcessName, pthread_getname_np failed with %{public}d", errno); - return ""; - } - std::string pthreadNameStr = pthreadName; - LOGI("RemoteFileShare::GetProcessName, thread name is %{public}s", pthreadNameStr.c_str()); - return pthreadNameStr; -} - -static std::string GetFileName(const int &fd) -{ - char buf[PATH_MAX] = {'\0'}; - char filePath[PATH_MAX] = {'\0'}; - - int ret = snprintf_s(buf, sizeof(buf), sizeof(buf), "/proc/self/fd/%d", fd); - if (ret < 0) { - LOGE("RemoteFileShare::GetFileName, snprintf failed with %{public}d", errno); - return ""; - } - - ret = readlink(buf, filePath, PATH_MAX); - if (ret < 0 || ret >= PATH_MAX) { - LOGE("RemoteFileShare::GetFileName, readlink failed with %{public}d", errno); - return ""; - } - - std::string fileName = filePath; - std::size_t firstSlash = fileName.rfind("/"); - if (firstSlash == fileName.npos) { - LOGE("RemoteFileShare::GetFileName, get error path with %{public}s", fileName.c_str()); - return ""; - } - fileName = fileName.substr(firstSlash + 1, fileName.size() - firstSlash); - return fileName; -} - -static int CreateShareDir(const std::string &path) -{ - if (access(path.c_str(), F_OK) != 0) { - int ret = mkdir(path.c_str(), S_IRWXU); - if (ret != 0) { - LOGE("RemoteFileShare::CreateShareDir, make dir failed with %{public}d", errno); - return errno; - } - } - return 0; -} - -static std::string GetSharePath(const int &userId, const std::string &packageName) -{ - return SHAER_PATH_HEAD + std::to_string(userId) + SHAER_PATH_MID + packageName; -} - -static std::string GetLowerSharePath(const int &userId, const std::string &packageName) -{ - return LOWER_SHARE_PATH_HEAD + std::to_string(userId) + LOWER_SHARE_PATH_MID + packageName; -} - -static bool DeleteShareDir(const std::string &PACKAGE_PATH, const std::string &SHARE_PATH) -{ - bool result = true; - if (access(SHARE_PATH.c_str(), F_OK) == 0) { - int ret = rmdir(SHARE_PATH.c_str()); - if (ret != 0) { - LOGE("RemoteFileShare::DeleteShareDir, delete dir failed with %{public}d", errno); - result = false; - } else { - LOGI("RemoteFileShare::DeleteShareDir, delete %{public}s path successfully", SHARE_PATH.c_str()); - } - } - if (access(PACKAGE_PATH.c_str(), F_OK) == 0) { - int ret = rmdir(PACKAGE_PATH.c_str()); - if (ret != 0) { - LOGE("RemoteFileShare::DeleteShareDir, delete dir failed with %{public}d", errno); - result = false; - } else { - LOGI("RemoteFileShare::DeleteShareDir, delete %{public}s path successfully", PACKAGE_PATH.c_str()); - } - } - return result; -} - -static int CreateShareFile(struct HmdfsShareControl &shareControl, const char* file, - const std::string &deviceId) -{ - int32_t dirFd = open(file, O_RDONLY); - if (dirFd < 0) { - LOGE("RemoteFileShare::CreateShareFile, open share path failed with %{public}d", errno); - return errno; - } - - memset_s(shareControl.deviceId, HMDFS_CID_SIZE, '\0', HMDFS_CID_SIZE); - if (memcpy_s(shareControl.deviceId, HMDFS_CID_SIZE, deviceId.c_str(), deviceId.size()) != 0) { - LOGE("RemoteFileShare::CreateShareFile, memcpy_s failed with %{public}d", errno); - close(dirFd); - return errno; - } - - if (ioctl(dirFd, HMDFS_IOC_SET_SHARE_PATH, &shareControl) < 0) { - LOGE("RemoteFileShare::CreateShareFile, ioctl failed with %{public}d", errno); - close(dirFd); - return errno; - } - close(dirFd); - return 0; -} - -static int CheckInputValidity(const int &fd, const int &userId, const std::string &deviceId) -{ - return (fd < 0) || (userId < USER_ID_INIT) || (deviceId != SHARE_ALL_DEVICE && - deviceId.size() != HMDFS_CID_SIZE); -} - -int RemoteFileShare::CreateSharePath(const int &fd, std::string &sharePath, - const int &userId, const std::string &deviceId) -{ - struct HmdfsShareControl shareControl; - shareControl.fd = fd; - - if (CheckInputValidity(fd, userId, deviceId) != 0) { - LOGE("RemoteFileShare::CreateSharePath, invalid argument with %{public}d", EINVAL); - return EINVAL; - } - - const std::string processName = GetProcessName(); - if (processName == "") { - LOGE("RemoteFileShare::CreateSharePath, GetProcessName failed with %{public}d", errno); - return errno; - } - - const std::string PACKAGE_PATH = GetLowerSharePath(userId, processName); - const std::string LOWER_SHARE_PATH = PACKAGE_PATH + "/.share"; - if (CreateShareDir(PACKAGE_PATH) != 0) - return errno; - if (CreateShareDir(LOWER_SHARE_PATH) != 0) { - DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); - return errno; - } - - const std::string SHARE_PATH = GetSharePath(userId, processName) + "/.share"; - char realPath[PATH_MAX] = {'\0'}; - if (!realpath(SHARE_PATH.c_str(), realPath)) { - LOGE("RemoteFileShare::CreateSharePath, realpath failed with %{public}d", errno); - DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); - return errno; - } - - std::string file_name = GetFileName(shareControl.fd); - if (file_name == "") { - LOGE("RemoteFileShare::CreateSharePath, get error file name"); - DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); - return EBADF; - } - sharePath = SHARE_PATH + "/" + file_name; - - if (CreateShareFile(shareControl, realPath, deviceId) != 0) { - LOGE("RemoteFileShare::CreateSharePath, create share file failed with %{public}d", errno); - /* When the file is exist, we should not delete the dictionary */ - if (errno == EEXIST) { - return 0; - } - sharePath = ""; - DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); - return errno; - } - LOGI("RemoteFileShare::CreateSharePath, create %{public}s successfully", sharePath.c_str()); - return 0; -} -} // namespace ModuleRemoteFileShare -} // namespace AppFileService -} // namespace OHOS -- Gitee From 0de3a6718e31b3d683a3e47cbf54f2789f92f518 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 6 Jul 2023 09:24:48 +0000 Subject: [PATCH 3/3] remote_file_share Signed-off-by: liuzerun --- bundle.json | 2 +- .../native/remote_file_share/BUILD.gn | 2 +- .../includ}/remote_file_share.h | 0 .../includ}/remote_file_share_log.h | 0 .../src/remote_file_share.cpp | 43 +++++++++--------- .../remote_file_share/native/BUILD.gn | 44 ------------------- test/unittest/remote_file_share/BUILD.gn | 2 +- 7 files changed, 25 insertions(+), 68 deletions(-) rename interfaces/innerkits/{remote_file_share/native => native/remote_file_share/includ}/remote_file_share.h (100%) rename interfaces/innerkits/{remote_file_share/native => native/remote_file_share/includ}/remote_file_share_log.h (100%) delete mode 100644 interfaces/innerkits/remote_file_share/native/BUILD.gn diff --git a/bundle.json b/bundle.json index c6e7d1fdf..786a53d00 100644 --- a/bundle.json +++ b/bundle.json @@ -79,7 +79,7 @@ "header_files": [ "remote_file_share.h" ], - "header_base": "//foundation/filemanagement/app_file_service/interfaces/innerkits/remote_file_share/native" + "header_base": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native/remote_file_share/include" } }, { diff --git a/interfaces/innerkits/native/remote_file_share/BUILD.gn b/interfaces/innerkits/native/remote_file_share/BUILD.gn index 051ab9355..6ce08fe7a 100644 --- a/interfaces/innerkits/native/remote_file_share/BUILD.gn +++ b/interfaces/innerkits/native/remote_file_share/BUILD.gn @@ -26,7 +26,7 @@ config("remote_file_share_config") { ohos_shared_library("remote_file_share_native") { sources = [ - "./src/remote_file_share.cpp", + "src/remote_file_share.cpp", "../../../common/src/common_func.cpp", ] diff --git a/interfaces/innerkits/remote_file_share/native/remote_file_share.h b/interfaces/innerkits/native/remote_file_share/includ/remote_file_share.h similarity index 100% rename from interfaces/innerkits/remote_file_share/native/remote_file_share.h rename to interfaces/innerkits/native/remote_file_share/includ/remote_file_share.h diff --git a/interfaces/innerkits/remote_file_share/native/remote_file_share_log.h b/interfaces/innerkits/native/remote_file_share/includ/remote_file_share_log.h similarity index 100% rename from interfaces/innerkits/remote_file_share/native/remote_file_share_log.h rename to interfaces/innerkits/native/remote_file_share/includ/remote_file_share_log.h 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 900549635..39f9662a2 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 @@ -35,7 +35,6 @@ namespace ModuleRemoteFileShare { namespace { const int HMDFS_CID_SIZE = 64; const int USER_ID_INIT = 100; - const int BUNDLENAME_BEGIN = 7; const unsigned HMDFS_IOC = 0xf2; const std::string URI_HEAD = "file://"; const std::string URI_MID = "/data/storage/el2/distributedfiles"; @@ -49,18 +48,18 @@ namespace { } #define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, struct HmdfsShareControl) -#define HMDFS_IOC_GET_DRAG_PATH _IOR(HMDFS_IOC, 3, unsigned int) +#define HMDFS_IOC_GET_DST_PATH _IOR(HMDFS_IOC, 3, unsigned int) struct HmdfsShareControl { int fd; char deviceId[HMDFS_CID_SIZE]; }; -struct HmdfsDragInfo { +struct HmdfsDstInfo { unsigned long localLen; unsigned long localPath; - unsigned long cloudLen; - unsigned long cloudPath; + unsigned long distributedLen; + unsigned long distributedPath; }; static std::string GetProcessName() @@ -181,27 +180,29 @@ static int CheckInputValidity(const int &fd, const int &userId, const std::strin } static int GetDistributedPath(const std::string &bundleName, const int &userId, - const std::string &physicalPath, std::string &distributedPath) + const std::string &physicalPath, std::string &distributedPath) { distributedPath = DST_PATH_HEAD + std::to_string(userId) + - DST_PATH_MID + bundleName + "/" + physicalPath; - if (int(distributedPath.size()) >= PATH_MAX) + DST_PATH_MID + bundleName + "/" + physicalPath; + if (distributedPath.size() >= PATH_MAX) { return -EINVAL; - else + } + else { return 0; + } } size_t GetFileSize(const std::string &fileName) { - size_t filesize; - struct stat statbuf; + size_t fileSize; + struct stat statBuf; if (fileName.empty()) { - return 0; + return 0; } - stat(fileName.c_str(), &statbuf); - filesize = statbuf.st_size; - return filesize; + stat(fileName.c_str(), &statBuf); + fileSize = statBuf.st_size; + return fileSize; } int RemoteFileShare::CreateSharePath(const int &fd, std::string &sharePath, @@ -273,8 +274,8 @@ int RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, std::string usingFile = SHAER_PATH_HEAD + std::to_string(userId) + SHAER_FILE_PATH; - struct HmdfsDragInfo hdi; - ret = AppFileService::CommonFunc::GetPhysicalPath(uriStr, + struct HmdfsDrstInfo hdi; + ret = CommonFunc::GetPhysicalPath(uriStr, std::to_string(userId), physicalPath); if (ret != 0) { LOGE("Failed to get lower path %{public}d", ret); @@ -291,7 +292,7 @@ int RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, return ret; } - ret = OHOS::ForceCreateDirectory(distributedPath.substr(0, + ret = ForceCreateDirectory(distributedPath.substr(0, distributedPath.find_last_of('/'))); if (ret == 1) { LOGE("Open distributed path failed"); @@ -308,10 +309,10 @@ int RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, distributedChar = distributedPath.c_str(); hdi.localLen = physicalPath.size() + 1; hdi.localPath = (unsigned long)(physicalChar); - hdi.cloudLen = distributedPath.size() + 1; - hdi.cloudPath = (unsigned long)(distributedChar); + hdi.distributedLen = distributedPath.size() + 1; + hdi.distributedPath = (unsigned long)(distributedChar); - ret = ioctl(hmdfsDevFd, HMDFS_IOC_GET_DRAG_PATH, hdi); + ret = ioctl(hmdfsDevFd, HMDFS_IOC_GET_DST_PATH, hdi); if (ret != 0) { LOGE("Ioctl failed %{public}d", ret); return ret; diff --git a/interfaces/innerkits/remote_file_share/native/BUILD.gn b/interfaces/innerkits/remote_file_share/native/BUILD.gn deleted file mode 100644 index 9fe39dba5..000000000 --- a/interfaces/innerkits/remote_file_share/native/BUILD.gn +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//foundation/filemanagement/app_file_service/app_file_service.gni") -config("remote_file_share_config") { - visibility = [ ":*" ] - include_dirs = [ - "include", - "${utils_system_safwk_path}/native/include", - "${path_base}/include", - ".", - ] -} - -ohos_shared_library("remote_file_share_native") { - sources = [ "${app_file_service_path}/services/remote_file_share/src/remote_file_share.cpp" ] - - public_configs = [ ":remote_file_share_config" ] - - external_deps = [ - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - ] - - defines = [ - "REMOTE_SHARE_FILE_LOG_TAG=\"RemoteFileShare\"", - "LOG_DOMAIN=0xD004312", - ] - - innerapi_tags = [ "platformsdk_indirect" ] - part_name = "app_file_service" - subsystem_name = "filemanagement" -} diff --git a/test/unittest/remote_file_share/BUILD.gn b/test/unittest/remote_file_share/BUILD.gn index 56084b209..04cdc2dd2 100644 --- a/test/unittest/remote_file_share/BUILD.gn +++ b/test/unittest/remote_file_share/BUILD.gn @@ -24,7 +24,7 @@ ohos_unittest("remote_file_share_test") { include_dirs = [ "include", - "../../../interfaces/innerkits/remote_file_share/native", + "../../../interfaces/innerkits/native/remote_file_share/include", "${utils_system_safwk_path}/native/include", "${path_base}/include", ] -- Gitee