diff --git a/BUILD.gn b/BUILD.gn index c70a22860ba06c0c465c5f8781bbf613cd91451a..7c57ae43d1239dc3c64a643c634da2b73fe4eed8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,7 +15,6 @@ 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/kits/js:remotefileshare", ] diff --git a/bundle.json b/bundle.json index 80107caf947ab6e6fc93c17487bd867923a43b21..8e3dea9aaa123cf57e431901202ae13329e8a501 100644 --- a/bundle.json +++ b/bundle.json @@ -51,6 +51,8 @@ "base_group": [], "fwk_group": [ "//foundation/filemanagement/app_file_service:libremotefileshare", + "//foundation/filemanagement/app_file_service/interfaces/innerkits/native:etc_files", + "//foundation/filemanagement/app_file_service/interfaces/innerkits/native:app_file_service_native", "//foundation/filemanagement/app_file_service/interfaces/kits/js:fileshare", "//foundation/filemanagement/app_file_service/interfaces/kits/js:fileuri", "//foundation/filemanagement/app_file_service/interfaces/kits/js:backup" @@ -64,7 +66,7 @@ }, "inner_kits": [ { - "name": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native/file_share:fileshare_native", + "name": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native:fileshare_native", "header": { "header_files": [ "file_share.h" diff --git a/interfaces/common/file_share_sandbox.json b/interfaces/common/file_share_sandbox.json new file mode 100644 index 0000000000000000000000000000000000000000..6accd84049a2d94ab05499d4bcc3249d69ecb006 --- /dev/null +++ b/interfaces/common/file_share_sandbox.json @@ -0,0 +1,37 @@ +{ + "mount-path-map" : [{ + "sandbox-path" : "/data/storage/el1/bundle", + "src-path" : "/data/app/el1/bundle/public/" + }, { + "sandbox-path" : "/data/storage/el2/base", + "src-path" : "/data/app/el2//base/" + }, { + "sandbox-path" : "/data/storage/el1/database", + "src-path" : "/data/app/el1//database/" + }, { + "sandbox-path" : "/data/storage/el2/database", + "src-path" : "/data/app/el2//database/" + }, { + "sandbox-path" : "/data/storage/el1/base", + "src-path" : "/data/app/el1//base/" + }, { + "sandbox-path" : "/data/storage/ark-cache", + "src-path" : "/data/local/ark-cache/" + }, { + "sandbox-path" : "/data/storage/ark-profile", + "src-path" : "/data/local/ark-profile//" + }, { + "sandbox-path" : "/data/storage/el2/distributedfiles", + "src-path" : "/mnt/hmdfs//account/merge_view/data/" + }, { + "sandbox-path" : "/mnt/data/fuse", + "src-path" : "/mnt/sandbox//mnt/data/fuse" + }, { + "sandbox-path" : "/storage/local/Documents", + "src-path" : "/mnt/hmdfs//account/merge_view/files/Documents" + }, { + "sandbox-path" : "/Documents", + "src-path" : "/mnt/hmdfs//account/merge_view/files/Documents" + } + ] +} \ No newline at end of file diff --git a/interfaces/kits/js/common/log.h b/interfaces/common/include/common_func.h similarity index 46% rename from interfaces/kits/js/common/log.h rename to interfaces/common/include/common_func.h index f9d3ece923ff4b0d30f3ad084309fd52c52ef4b3..cbeb03d3b1419e3123bec1bd66cec2904b2af103 100644 --- a/interfaces/kits/js/common/log.h +++ b/interfaces/common/include/common_func.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -12,25 +12,23 @@ * 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 }; +#ifndef FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_INNERKITS_NATIVE_COMMON_INCLUDE_COMMON_FUNC_H +#define FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_INNERKITS_NATIVE_COMMON_INCLUDE_COMMON_FUNC_H -#define PRINT_LOG(Level, fmt, ...) \ - OHOS::HiviewDFX::HiLog::Level(OHOS::AppFileService::LOG_LABEL, "[%{public}s:%{public}d] " fmt, \ - __FUNCTION__, __LINE__, ##__VA_ARGS__) +#include +#include -#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 OHOS { +namespace AppFileService { +class CommonFunc { + static std::unordered_map sandboxPathMap_; +public: + static bool CheckValidPath(const std::string &filePath); + static int32_t GetPhysicalPath(const std::string &fileUri, const std::string &userId, + std::string &physicalPath); +}; } // namespace AppFileService } // namespace OHOS -#endif // LOG_H \ No newline at end of file +#endif // FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_INNERKITS_NATIVE_COMMON_INCLUDE_COMMON_FUNC_H \ No newline at end of file diff --git a/interfaces/common/include/json_utils.h b/interfaces/common/include/json_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..eab454018bb48fb29143bfc7f84ab6725fb18b2f --- /dev/null +++ b/interfaces/common/include/json_utils.h @@ -0,0 +1,35 @@ +/* + * 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 FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_COMMON_INCLUDE_JSON_UTILS_H +#define FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_COMMON_INCLUDE_JSON_UTILS_H + +#include +#include +#include + +#include "nlohmann/json.hpp" + +namespace OHOS { +namespace AppFileService { +class JsonUtils { +public: + static int32_t GetJsonObjFromPath(nlohmann::json& jsonObj, const std::string& jsonPath); + static int32_t GetKVFromJson(const nlohmann::json &json, const std::string &key, + std::string &value); +}; +} // AppFileService +} // OHOS +#endif // FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_COMMON_INCLUDE_JSON_UTILS_H diff --git a/interfaces/innerkits/native/common/log.h b/interfaces/common/include/log.h similarity index 84% rename from interfaces/innerkits/native/common/log.h rename to interfaces/common/include/log.h index 7504b3f37f3bada618cf97ba4f60d5f76e17d021..9f7053a45a41fc1dcff07f469cdb61702bfdc2f8 100644 --- a/interfaces/innerkits/native/common/log.h +++ b/interfaces/common/include/log.h @@ -12,8 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LOG_H -#define LOG_H +#ifndef FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_INNERKITS_NATIVE_COMMON_LOG_H +#define FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_INNERKITS_NATIVE_COMMON_LOG_H + #include "hilog/log.h" namespace OHOS { @@ -33,4 +34,4 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, APP_LOG_DOM } // namespace AppFileService } // namespace OHOS -#endif // LOG_H \ No newline at end of file +#endif // FILEMANAGEMENT_APP_FILE_SERVICE_INTERFACES_INNERKITS_NATIVE_COMMON_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 0000000000000000000000000000000000000000..fae72c9d98339f77d2e6f640b2b561cfed75b994 --- /dev/null +++ b/interfaces/common/src/common_func.cpp @@ -0,0 +1,127 @@ +/* + * 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 "log.h" +#include "json_utils.h" +#include "uri.h" + +using namespace std; + +namespace OHOS { +namespace AppFileService { +namespace { + const string PACKAGE_NAME_FLAG = ""; + const string CURRENT_USER_ID_FLAG = ""; + const string PHYSICAL_PATH_KEY = "src-path"; + const string SANDBOX_PATH_KEY = "sandbox-path"; + const string MOUNT_PATH_MAP_KEY = "mount-path-map"; + const string SANDBOX_JSON_FILE_PATH = "/etc/app_file_service/file_share_sandbox.json"; +} +std::unordered_map CommonFunc::sandboxPathMap_; + +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; +} + +static void GetSandboxPathMap(unordered_map &sandboxPathMap) +{ + nlohmann::json jsonObj; + int ret = JsonUtils::GetJsonObjFromPath(jsonObj, SANDBOX_JSON_FILE_PATH); + if (ret != 0) { + LOGE("Get json object failed from %{public}s with %{public}d", SANDBOX_JSON_FILE_PATH.c_str(), ret); + return; + } + + if (jsonObj.find(MOUNT_PATH_MAP_KEY) == jsonObj.end()) { + LOGE("Json object find mount path map failed"); + return; + } + + nlohmann::json mountPathMap = jsonObj[MOUNT_PATH_MAP_KEY]; + for (size_t i = 0; i < mountPathMap.size(); i++) { + string srcPath = mountPathMap[i][PHYSICAL_PATH_KEY]; + string sandboxPath = mountPathMap[i][SANDBOX_PATH_KEY]; + sandboxPathMap[sandboxPath] = srcPath; + } + return; +} + +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 = ""; + + if (sandboxPathMap_.size() == 0) { + GetSandboxPathMap(sandboxPathMap_); + } + + for (auto it = sandboxPathMap_.begin(); it != sandboxPathMap_.end(); it++) { + string sandboxPathPrefix = it->first; + if (sandboxPath.length() >= sandboxPathPrefix.length()) { + string sandboxPathTemp = sandboxPath.substr(0, sandboxPathPrefix.length()); + if (sandboxPathTemp == sandboxPathPrefix) { + lowerPathHead = it->second; + lowerPathTail = sandboxPath.substr(sandboxPathPrefix.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/common/src/json_utils.cpp b/interfaces/common/src/json_utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb6ffc6cd120482f764271a2118dbd1b3d885910 --- /dev/null +++ b/interfaces/common/src/json_utils.cpp @@ -0,0 +1,67 @@ +/* + * 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 "json_utils.h" + +#include +#include + +#include "common_func.h" +#include "log.h" + +namespace OHOS { +namespace AppFileService { + +int32_t JsonUtils::GetJsonObjFromPath(nlohmann::json& jsonObj, const std::string& jsonPath) +{ + std::ifstream jsonFileStream; + jsonFileStream.open(jsonPath.c_str(), std::ios::in); + if (!jsonFileStream.is_open()) { + LOGE("Open json file path %{public}s failed with error %{public}d", jsonPath.c_str(), errno); + return -errno; + } + + std::ostringstream buf; + char ch; + while (buf && jsonFileStream.get(ch)) { + buf.put(ch); + } + jsonFileStream.close(); + + jsonObj = nlohmann::json::parse(buf.str(), nullptr, false); + if (!jsonObj.is_structured()) { + LOGE("Parse json file path %{public}s failed", jsonPath.c_str()); + } + return 0; +} + +int32_t JsonUtils::GetKVFromJson(const nlohmann::json &json, const std::string &key, + std::string &value) +{ + if (!json.is_object()) { + LOGE("Invalid json object"); + return -EINVAL; + } + + bool ret = json.find(key) != json.end() && json.at(key).is_string(); + if (ret) { + value = json.at(key).get(); + return 0; + } else { + return -EINVAL; + } +} + +} // AppFileService +} // OHOS \ No newline at end of file diff --git a/interfaces/innerkits/native/file_share/BUILD.gn b/interfaces/innerkits/native/BUILD.gn similarity index 64% rename from interfaces/innerkits/native/file_share/BUILD.gn rename to interfaces/innerkits/native/BUILD.gn index 07ff0407b32a7db66f7f79fde9b058343e71a3f3..520727f89246d2ec4b8507b07362ca5ad00423a2 100644 --- a/interfaces/innerkits/native/file_share/BUILD.gn +++ b/interfaces/innerkits/native/BUILD.gn @@ -16,13 +16,18 @@ import("//build/ohos.gni") config("file_share_config") { visibility = [ ":*" ] include_dirs = [ - "include", - "../common", + "file_share/include", + "//third_party/json/include", + "../../common/include", ] } ohos_shared_library("fileshare_native") { - sources = [ "src/file_share.cpp" ] + sources = [ + "../../common/src/common_func.cpp", + "../../common/src/json_utils.cpp", + "file_share/src/file_share.cpp", + ] public_configs = [ ":file_share_config" ] @@ -38,3 +43,18 @@ ohos_shared_library("fileshare_native") { part_name = "app_file_service" subsystem_name = "filemanagement" } + +ohos_prebuilt_etc("file_share_sandbox.json") { + source = "../../common/file_share_sandbox.json" + part_name = "app_file_service" + subsystem_name = "filemanagement" + module_install_dir = "etc/app_file_service" +} + +group("app_file_service_native") { + deps = [ ":fileshare_native" ] +} + +group("etc_files") { + deps = [ ":file_share_sandbox.json" ] +} diff --git a/interfaces/innerkits/native/file_share/include/file_share.h b/interfaces/innerkits/native/file_share/include/file_share.h index 8f7c3430204f60e1fbbef530ccb0cacdaf013265..cf1178c6fb89429e7c3fd19a943b1de936ba199b 100644 --- a/interfaces/innerkits/native/file_share/include/file_share.h +++ b/interfaces/innerkits/native/file_share/include/file_share.h @@ -24,48 +24,6 @@ namespace OHOS { namespace AppFileService { using namespace std; -#define DIR_MODE (S_IRWXU | S_IXGRP | S_IXOTH) -#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) -#define READ_URI_PERMISSION OHOS::AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION -#define WRITE_URI_PERMISSION OHOS::AAFwk::Want::FLAG_AUTH_WRITE_URI_PERMISSION - -enum SHARE_FILE_TYPE { DIR_TYPE = 0, FILE_TYPE }; - -namespace { -const string FILE_SCHEME = "file"; -const string PACKAGE_NAME_FLAG = ""; -const string CURRENT_USER_ID_FLAG = ""; -const string DATA_APP_EL2_PATH = "/data/service/el2/"; -const string SHARE_R_PATH = "/r/"; -const string SHARE_RW_PATH = "/rw/"; -const string SHARE_PATH = "/share/"; -const string DLP_MANAGER_BUNDLE_NAME = "com.ohos.dlpmanager"; - -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" -}; - -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" -}; -} - #ifdef __cplusplus #if __cplusplus extern "C" { diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index f7cb9ba01acfab930aa96a2d167bbaf4ea00dda6..22b56a4fec891df4cdaab277103e684040e62813 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -23,12 +23,30 @@ #include #include "accesstoken_kit.h" +#include "common_func.h" #include "hap_token_info.h" #include "log.h" #include "uri.h" namespace OHOS { namespace AppFileService { +#define DIR_MODE (S_IRWXU | S_IXGRP | S_IXOTH) +#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) +#define READ_URI_PERMISSION OHOS::AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION +#define WRITE_URI_PERMISSION OHOS::AAFwk::Want::FLAG_AUTH_WRITE_URI_PERMISSION + +enum ShareFileType { + DIR_TYPE = 0, + FILE_TYPE = 1, +}; + +namespace { +const string FILE_SCHEME = "file"; +const string DATA_APP_EL2_PATH = "/data/service/el2/"; +const string SHARE_R_PATH = "/r/"; +const string SHARE_RW_PATH = "/rw/"; +const string SHARE_PATH = "/share/"; +} struct FileShareInfo { string providerBundleName_; @@ -38,7 +56,7 @@ struct FileShareInfo { vector sharePath_; vector isExist_; string currentUid_; - SHARE_FILE_TYPE type_; + ShareFileType type_; }; static int32_t GetTargetInfo(uint32_t tokenId, string &bundleName, string ¤tUid) @@ -59,10 +77,11 @@ static int32_t GetTargetInfo(uint32_t tokenId, string &bundleName, string &curre return 0; } -static void GetProviderBundleName(string uriStr, string &bundleName) +static void GetProviderInfo(string uriStr, FileShareInfo &info) { Uri uri(uriStr); - bundleName = uri.GetAuthority(); + info.providerBundleName_ = uri.GetAuthority(); + info.providerSandboxPath_ = uri.GetPath(); } static bool IsExistDir(const string &path) @@ -84,54 +103,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(); - 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_ + @@ -152,10 +123,10 @@ static void GetSharePath(FileShareInfo &info, uint32_t flag) static int32_t GetShareFileType(FileShareInfo &info) { if (IsExistFile(info.providerLowerPath_)) { - info.type_ = FILE_TYPE; + info.type_ = ShareFileType::FILE_TYPE; return 0; } else if (IsExistDir(info.providerLowerPath_)) { - info.type_ = DIR_TYPE; + info.type_ = ShareFileType::DIR_TYPE; return 0; } return -ENOENT; @@ -170,8 +141,9 @@ static int32_t GetFileShareInfo(const string &uri, uint32_t tokenId, uint32_t fl return ret; } - GetProviderBundleName(uri, info.providerBundleName_); - ret = GetProviderPath(uri, info); + GetProviderInfo(uri, info); + + ret = CommonFunc::GetPhysicalPath(uri, info.currentUid_, info.providerLowerPath_); if (ret != 0) { LOGE("Failed to get lower path %{public}d", ret); return ret; @@ -182,6 +154,7 @@ static int32_t GetFileShareInfo(const string &uri, uint32_t tokenId, uint32_t fl LOGE("Failed to get share file type %{public}d", ret); return ret; } + GetSharePath(info, flag); return 0; } @@ -209,24 +182,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; } @@ -267,15 +225,15 @@ int32_t CreateShareFile(const string &uri, uint32_t tokenId, uint32_t flag) continue; } - if (info.type_ == FILE_TYPE) { + if (info.type_ == ShareFileType::FILE_TYPE) { if ((ret = creat(info.sharePath_[i].c_str(), FILE_MODE)) < 0) { LOGE("Create file failed with %{public}d", errno); return -errno; } close(ret); - } else if (mkdir(info.sharePath_[i].c_str(), DIR_MODE) != 0) { - LOGE("Create dir failed with %{public}d", errno); - return -errno; + } else { + LOGE("Invalid argument not support dir to share"); + return -EINVAL; } if (mount(info.providerLowerPath_.c_str(), info.sharePath_[i].c_str(), diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 5c68b54c5a9236662ab094b39cd109ea3052454a..b93c1e0850ecf5274dc474ea807e5edab017812f 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 = [