diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 431e4fd588272435ec1d67100e5c6f4e2aa92fb2..7940baeed4b88fea99dd06141b7cd7ec69990d35 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);