diff --git a/interfaces/innerkits/native/file_share/include/file_share.h b/interfaces/innerkits/native/file_share/include/file_share.h index cf1178c6fb89429e7c3fd19a943b1de936ba199b..9d97157cc85a57177ec5a36feb815e794518b8dc 100644 --- a/interfaces/innerkits/native/file_share/include/file_share.h +++ b/interfaces/innerkits/native/file_share/include/file_share.h @@ -31,6 +31,7 @@ extern "C" { #endif /* End of #ifdef __cplusplus */ int32_t CreateShareFile(const string &uri, uint32_t tokenId, uint32_t flag); int32_t DeleteShareFile(uint32_t tokenId, vector sharePathList); + int32_t CreateShareFileList(const vector &uriList, uint32_t tokenId, uint32_t flag); #ifdef __cplusplus #if __cplusplus } diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index f59856995938a3f339345c4dc09cfebe60f625d4..56776feb25de6b9dc22b5db2db96cb82bad3ad83 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -285,6 +285,46 @@ int32_t CreateShareFile(const string &uri, uint32_t tokenId, uint32_t flag) return 0; } +static void DelSharePath(const string &delPath) +{ + if (!SandboxHelper::CheckValidPath(delPath)) { + LOGE("DelSharePath, umount path is invalid, path = %{private}s", delPath.c_str()); + return; + } + + if (access(delPath.c_str(), F_OK) == 0) { + if (umount2(delPath.c_str(), MNT_DETACH) != 0) { + LOGE("DelSharePath, umount failed with %{public}d", errno); + } + remove(delPath.c_str()); + } +} + +int32_t CreateShareFileList(const vector &uriList, uint32_t tokenId, uint32_t flag) +{ + for (size_t i = 0; i < uriList.size(); i++) { + (void)CreateShareFile(uriList[i], tokenId, flag); + } + + return 0; +} + +static void UmountDelUris(vector sharePathList, string currentUid, string bundleNameSelf) +{ + string delPathPrefix = DATA_APP_EL2_PATH + currentUid + SHARE_PATH + bundleNameSelf; + for (size_t i = 0; i < sharePathList.size(); i++) { + Uri uri(SandboxHelper::Decode(sharePathList[i])); + string path = uri.GetPath(); + string bundleName = uri.GetAuthority(); + + string delRPath = delPathPrefix + SHARE_R_PATH + bundleName + path; + DelSharePath(delRPath); + + string delRWPath = delPathPrefix + SHARE_RW_PATH + bundleName + path; + DelSharePath(delRWPath); + } +} + int32_t DeleteShareFile(uint32_t tokenId, vector sharePathList) { string bundleName, currentUid;