From 6a8dd999c65af66c25832fc99b55f22d86e650ab Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Tue, 12 Mar 2024 09:28:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E8=AE=BE=E5=A4=87=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E4=BA=AB=E8=B7=AF=E5=BE=84=E8=BD=AC=E6=8D=A2=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 | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 7cb30614f..d72f3eec3 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -60,6 +60,7 @@ struct FileShareInfo { vector sharePath_; string currentUid_; ShareFileType type_; + ino_t stIno_; }; mutex FileShare::mapMutex_; @@ -89,26 +90,28 @@ static void GetProviderInfo(string uriStr, FileShareInfo &info) info.providerSandboxPath_ = SandboxHelper::Decode(uri.GetPath()); } -static bool IsExistDir(const string &path) +static bool IsExistDir(const string &path, FileShareInfo &info) { struct stat buf = {}; if (stat(path.c_str(), &buf) != 0) { return false; } + info.stIno_ = buf.st_ino; return S_ISDIR(buf.st_mode); } -static bool IsExistFile(const string &path) +static bool IsExistFile(const string &path, FileShareInfo &info) { struct stat buf = {}; if (stat(path.c_str(), &buf) != 0) { LOGE("Get path stat failed, err %{public}d", errno); return false; } + info.stIno_ = buf.st_ino; return S_ISREG(buf.st_mode); } -static bool CheckIfNeedShare(const string &uriStr, ShareFileType type, const string &path) +static bool CheckIfNeedShare(const string &uriStr, ShareFileType type, FileShareInfo &info, const string &path) { if (type == ShareFileType::DIR_TYPE) { return true; @@ -121,7 +124,8 @@ static bool CheckIfNeedShare(const string &uriStr, ShareFileType type, const str Uri uri(uriStr); string networkIdInfo = uri.GetQuery(); - if (buf.st_nlink != 0 || (!networkIdInfo.empty() && networkIdInfo.find(NETWORK_PARA) == 0)) { + if ((buf.st_nlink != 0 || (!networkIdInfo.empty() && networkIdInfo.find(NETWORK_PARA) == 0)) && + buf.st_ino == info.stIno_) { LOGI("no need create again"); return false; } @@ -141,12 +145,12 @@ static int32_t GetSharePath(const string &uri, FileShareInfo &info, uint32_t fla return -EINVAL; } - if (CheckIfNeedShare(uri, info.type_, shareRPath)) { + if (CheckIfNeedShare(uri, info.type_, info, shareRPath)) { info.sharePath_.push_back(shareRPath); } if ((flag & WRITE_URI_PERMISSION) == WRITE_URI_PERMISSION && - CheckIfNeedShare(uri, info.type_, shareRWPath)) { + CheckIfNeedShare(uri, info.type_, info, shareRWPath)) { info.sharePath_.push_back(shareRWPath); } @@ -160,10 +164,10 @@ static int32_t GetShareFileType(FileShareInfo &info) return -EINVAL; } - if (IsExistFile(info.providerLowerPath_)) { + if (IsExistFile(info.providerLowerPath_, info)) { info.type_ = ShareFileType::FILE_TYPE; return 0; - } else if (IsExistDir(info.providerLowerPath_)) { + } else if (IsExistDir(info.providerLowerPath_, info)) { info.type_ = ShareFileType::DIR_TYPE; return 0; } -- Gitee