From 311b00e3b4c86e8436ef6e5aac285f44a46fa7e9 Mon Sep 17 00:00:00 2001 From: lwx1249696 Date: Fri, 17 Nov 2023 09:51:20 +0800 Subject: [PATCH] add share dir Signed-off-by: lwx1249696 --- .../native/file_share/src/file_share.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 431e4fd58..7940baeed 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -271,17 +271,21 @@ static int32_t CreateSingleShareFile(const string &uri, uint32_t tokenId, uint32 return ret; } - if (info.type_ != ShareFileType::FILE_TYPE) { - LOGE("Invalid argument not support dir to share"); - return -EINVAL; - } - for (size_t i = 0; i < info.sharePath_.size(); i++) { - if ((ret = open(info.sharePath_[i].c_str(), O_RDONLY | O_CREAT)) < 0) { - LOGE("Create file failed with %{public}d", errno); - return -errno; + if (info.type_ == ShareFileType::FILE_TYPE) { + if ((ret = open(info.sharePath_[i].c_str(), O_RDONLY | O_CREAT)) < 0) { + LOGE("Create file failed with %{public}d", errno); + return -errno; + } + close(ret); + } else { + if (access(info.sharePath_[i].c_str(), 0) != 0 && + mkdir(info.sharePath_[i].c_str(), DIR_MODE) != 0) { + LOGE("Failed to make dir with %{public}d", errno); + return -errno; + } } - close(ret); + if (mount(info.providerLowerPath_.c_str(), info.sharePath_[i].c_str(), nullptr, MS_BIND, nullptr) != 0) { LOGE("Mount failed with %{public}d", errno); -- Gitee