From eef253dcff134da48c89cd682da124a32f63e512 Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Mon, 14 Apr 2025 16:57:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E8=AE=BE=E5=A4=87=E5=88=86=E4=BA=ABRW?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E5=90=8E=E6=BA=90=E6=96=87=E4=BB=B6=E8=A2=AB?= =?UTF-8?q?=E5=88=A0=E9=99=A4=EF=BC=8C=E5=88=B7=E6=96=B0r=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E6=8C=82=E8=BD=BD=E7=82=B9=E6=97=B6=E5=B0=86RW?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=8D=B8=E8=BD=BD=E5=88=A0=E9=99=A4=20Signed?= =?UTF-8?q?-off-by:=20cuiruibin=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../native/file_share/src/file_share.cpp | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 0c954afab..ddaa5ea9f 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -139,6 +139,23 @@ static bool CheckIfNeedShare(const string &uriStr, ShareFileType type, FileShare return true; } +static void DelSharePath(const string &delPath) +{ + if (!SandboxHelper::CheckValidPath(delPath)) { + LOGE("DelSharePath, umount path is invalid"); + 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); + } + if (remove(delPath.c_str()) != 0) { + LOGE("DelSharePath, remove failed with %{public}d", errno); + } + } +} + static int32_t GetSharePath(const string &uri, FileShareInfo &info, uint32_t flag) { string shareRPath = DATA_APP_EL2_PATH + info.currentUid_ + SHARE_PATH + info.targetBundleName_ + @@ -153,6 +170,7 @@ static int32_t GetSharePath(const string &uri, FileShareInfo &info, uint32_t fla if (CheckIfNeedShare(uri, info.type_, info, shareRPath)) { info.sharePath_.push_back(shareRPath); + DelSharePath(shareRWPath); } if ((flag & WRITE_URI_PERMISSION) == WRITE_URI_PERMISSION && @@ -244,23 +262,6 @@ static bool DeleteExistShareFile(const string &path) return true; } -static void DelSharePath(const string &delPath) -{ - if (!SandboxHelper::CheckValidPath(delPath)) { - LOGE("DelSharePath, umount path is invalid"); - 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); - } - if (remove(delPath.c_str()) != 0) { - LOGE("DelSharePath, remove failed with %{public}d", errno); - } - } -} - static void UmountDelUris(vector sharePathList, string currentUid, string bundleNameSelf) { string delPathPrefix = DATA_APP_EL2_PATH + currentUid + SHARE_PATH + bundleNameSelf; -- Gitee