From 9d30f718eba3bbd65dc5312d35556f07630fd228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=87=AF=E7=A5=A5?= Date: Thu, 20 Jul 2023 10:10:25 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!197=20:?= =?UTF-8?q?=20=E9=87=8D=E5=A4=8D=E5=88=86=E4=BA=AB=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=B6=E5=88=A0=E9=99=A4=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E6=98=A0=E5=B0=84=E6=96=87=E4=BB=B6'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../native/file_share/src/file_share.cpp | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 5cfea0e65..22b56a4fe 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -54,6 +54,7 @@ struct FileShareInfo { string providerLowerPath_; string providerSandboxPath_; vector sharePath_; + vector isExist_; string currentUid_; ShareFileType type_; }; @@ -111,8 +112,11 @@ static void GetSharePath(FileShareInfo &info, uint32_t flag) if ((flag & WRITE_URI_PERMISSION) == WRITE_URI_PERMISSION) { info.sharePath_.push_back(shareRWPath); info.sharePath_.push_back(shareRPath); + info.isExist_.push_back(false); + info.isExist_.push_back(false); } else if ((flag & READ_URI_PERMISSION) == READ_URI_PERMISSION) { info.sharePath_.push_back(shareRPath); + info.isExist_.push_back(false); } } @@ -178,16 +182,6 @@ static bool MakeDir(const string &path) return true; } -static void DeleteExistShareFile(const string &path) -{ - if (access(path.c_str(), F_OK) == 0) { - if (umount2(path.c_str(), MNT_DETACH) != 0) { - LOGE("Umount failed with %{public}d", errno); - } - remove(path.c_str()); - } -} - static int32_t PreparePreShareDir(FileShareInfo &info) { if (!CommonFunc::CheckValidPath(info.providerLowerPath_)) { @@ -205,7 +199,8 @@ static int32_t PreparePreShareDir(FileShareInfo &info) return -errno; } } else { - DeleteExistShareFile(info.sharePath_[i]); + LOGE("File %{public}s already exists", info.sharePath_[i].c_str()); + info.isExist_[i] = true; } } return 0; @@ -226,6 +221,10 @@ int32_t CreateShareFile(const string &uri, uint32_t tokenId, uint32_t flag) } for (size_t i = 0; i < info.sharePath_.size(); i++) { + if (info.isExist_[i]) { + continue; + } + 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); -- Gitee