mirror of
https://gitee.com/openharmony/filemanagement_user_file_service
synced 2024-11-27 01:21:32 +00:00
feat: implement listFile interface based on shared memory
Signed-off-by: caochuan <caochuan@huawei.com>
This commit is contained in:
parent
c07db6d631
commit
14745d21d5
@ -20,3 +20,4 @@ access_token_path = "//base/security/access_token"
|
||||
file_api_path = "//foundation/filemanagement/file_api"
|
||||
user_file_service_path = "//foundation/filemanagement/user_file_service"
|
||||
distributed_file_path = "//foundation/distributeddatamgr/distributedfile"
|
||||
commonlibrary_path = "//commonlibrary"
|
||||
|
@ -22,21 +22,29 @@
|
||||
#include "file_access_helper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "file_filter.h"
|
||||
#include "file_info_shared_memory.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace FileAccessFwk {
|
||||
|
||||
constexpr int64_t MAX_COUNT = 200; // ListFile get file's max count
|
||||
constexpr int CALL_LISTFILE = 0;
|
||||
constexpr int CALL_SCANFILE = 1;
|
||||
|
||||
struct FileIteratorEntity {
|
||||
~FileIteratorEntity() {
|
||||
SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
FileAccessHelper *fileAccessHelper { nullptr };
|
||||
std::mutex entityOperateMutex;
|
||||
FileInfo fileInfo;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
SharedMemoryInfo memInfo;
|
||||
int64_t offset { 0 };
|
||||
uint64_t pos { 0 };
|
||||
uint32_t currentDataCounts { 0 };
|
||||
FileFilter filter { {}, {}, {}, FileFilter::INVALID_SIZE, FileFilter::INVALID_MODIFY_AFTER, false, false };
|
||||
int flag { 0 };
|
||||
int flag { CALL_LISTFILE };
|
||||
};
|
||||
} // namespace FileAccessFwk
|
||||
} // namespace OHOS
|
||||
|
@ -119,18 +119,25 @@ napi_value NapiFileInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(fileIteratorEntity->entityOperateMutex);
|
||||
int ret = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfoList", DEFAULT_CAPACITY_200KB,
|
||||
fileIteratorEntity->memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fileIteratorEntity->fileAccessHelper = fileInfoEntity->fileAccessHelper;
|
||||
fileIteratorEntity->fileInfo = fileInfoEntity->fileInfo;
|
||||
fileIteratorEntity->fileInfoVec.clear();
|
||||
fileIteratorEntity->offset = 0;
|
||||
fileIteratorEntity->pos = 0;
|
||||
fileIteratorEntity->filter = std::move(filter);
|
||||
fileIteratorEntity->flag = 0;
|
||||
auto ret = fileInfoEntity->fileAccessHelper->ListFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset,
|
||||
MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec);
|
||||
fileIteratorEntity->flag = CALL_LISTFILE;
|
||||
ret = fileInfoEntity->fileAccessHelper->ListFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset,
|
||||
fileIteratorEntity->filter, fileIteratorEntity->memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(fileIteratorEntity->memInfo);
|
||||
return ThrowError(env, ret);
|
||||
}
|
||||
fileIteratorEntity->currentDataCounts = fileIteratorEntity->memInfo.totalDataCounts;
|
||||
}
|
||||
return NVal(env, objFileIteratorExporter).val_;
|
||||
}
|
||||
@ -173,9 +180,8 @@ napi_value NapiFileInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
fileIteratorEntity->fileInfo = fileInfoEntity->fileInfo;
|
||||
fileIteratorEntity->fileInfoVec.clear();
|
||||
fileIteratorEntity->offset = 0;
|
||||
fileIteratorEntity->pos = 0;
|
||||
fileIteratorEntity->filter = std::move(filter);
|
||||
fileIteratorEntity->flag = 1;
|
||||
fileIteratorEntity->flag = CALL_SCANFILE;
|
||||
auto ret = fileInfoEntity->fileAccessHelper->ScanFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset,
|
||||
MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
|
@ -74,7 +74,44 @@ napi_value NapiFileIteratorExporter::Constructor(napi_env env, napi_callback_inf
|
||||
return funcArg.GetThisVar();
|
||||
}
|
||||
|
||||
static int MakeResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileIteratorEntity,
|
||||
static int MakeListFileResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileIteratorEntity,
|
||||
FileInfoEntity *fileInfoEntity, napi_env env, NVal &nVal, bool &isDone)
|
||||
{
|
||||
SharedMemoryInfo &memInfo = fileIteratorEntity->memInfo;
|
||||
std::lock_guard<std::mutex> lock(fileIteratorEntity->entityOperateMutex);
|
||||
if (memInfo.Empty() && !memInfo.isOver) {
|
||||
int ret = SharedMemoryOperation::ExpandSharedMemory(memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
fileIteratorEntity->offset += fileIteratorEntity->currentDataCounts;
|
||||
ret = fileIteratorEntity->fileAccessHelper->ListFile(fileIteratorEntity->fileInfo,
|
||||
fileIteratorEntity->offset, fileIteratorEntity->filter, memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("exec ListFile fail, code:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
fileIteratorEntity->currentDataCounts = fileIteratorEntity->memInfo.totalDataCounts;
|
||||
}
|
||||
|
||||
fileInfoEntity->fileAccessHelper = fileIteratorEntity->fileAccessHelper;
|
||||
auto ret = SharedMemoryOperation::ReadFileInfo(fileInfoEntity->fileInfo, memInfo);
|
||||
if (!ret) {
|
||||
fileInfoEntity = nullptr;
|
||||
objFileInfoExporter = NVal::CreateUndefined(env).val_;
|
||||
nVal.AddProp("value", objFileInfoExporter);
|
||||
nVal.AddProp("done", NVal::CreateBool(env, true).val_);
|
||||
isDone = true;
|
||||
return ERR_OK;
|
||||
}
|
||||
nVal.AddProp("value", objFileInfoExporter);
|
||||
nVal.AddProp("done", NVal::CreateBool(env, false).val_);
|
||||
isDone = false;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static int MakeScanFileResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileIteratorEntity,
|
||||
FileInfoEntity *fileInfoEntity, napi_env env, NVal &nVal, bool &isDone)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(fileIteratorEntity->entityOperateMutex);
|
||||
@ -93,14 +130,6 @@ static int MakeResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileI
|
||||
fileIteratorEntity->fileInfoVec.clear();
|
||||
fileIteratorEntity->offset += MAX_COUNT;
|
||||
fileIteratorEntity->pos = 0;
|
||||
if (fileIteratorEntity->flag == 0) {
|
||||
int ret = fileIteratorEntity->fileAccessHelper->ListFile(fileIteratorEntity->fileInfo,
|
||||
fileIteratorEntity->offset, MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("exec ListFile fail, code:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
} else if (fileIteratorEntity->flag == 1) {
|
||||
int ret = fileIteratorEntity->fileAccessHelper->ScanFile(fileIteratorEntity->fileInfo,
|
||||
fileIteratorEntity->offset, MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
@ -108,7 +137,6 @@ static int MakeResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileI
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fileIteratorEntity->pos == fileIteratorEntity->fileInfoVec.size()) {
|
||||
fileIteratorEntity->fileInfoVec.clear();
|
||||
fileIteratorEntity->offset = 0;
|
||||
@ -174,20 +202,28 @@ napi_value NapiFileIteratorExporter::Next(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
auto retNVal = NVal::CreateObject(env);
|
||||
int ret = E_GETRESULT;
|
||||
bool isDone = false;
|
||||
int ret = MakeResult(objFileInfoExporter, fileIteratorEntity, fileInfoEntity, env, retNVal, isDone);
|
||||
if (fileIteratorEntity->flag == CALL_LISTFILE) {
|
||||
ret = MakeListFileResult(objFileInfoExporter, fileIteratorEntity, fileInfoEntity, env, retNVal, isDone);
|
||||
} else if (fileIteratorEntity->flag == CALL_SCANFILE) {
|
||||
ret = MakeScanFileResult(objFileInfoExporter, fileIteratorEntity, fileInfoEntity, env, retNVal, isDone);
|
||||
}
|
||||
while (!isDone && FilterTrashAndRecentDir(fileInfoEntity->fileInfo.uri)) {
|
||||
fileInfoEntity = NClass::GetEntityOf<FileInfoEntity>(env, objFileInfoExporter);
|
||||
retNVal = NVal::CreateObject(env);
|
||||
HILOG_DEBUG("TRASH_DIR or RECENT_DIR: %{public}s", fileInfoEntity->fileInfo.uri.c_str());
|
||||
ret = MakeResult(objFileInfoExporter, fileIteratorEntity, fileInfoEntity, env, retNVal, isDone);
|
||||
if (fileIteratorEntity->flag == CALL_LISTFILE) {
|
||||
ret = MakeListFileResult(objFileInfoExporter, fileIteratorEntity, fileInfoEntity, env, retNVal, isDone);
|
||||
} else if (fileIteratorEntity->flag == CALL_SCANFILE) {
|
||||
ret = MakeScanFileResult(objFileInfoExporter, fileIteratorEntity, fileInfoEntity, env, retNVal, isDone);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return retNVal.val_;
|
||||
}
|
||||
|
||||
|
@ -115,16 +115,21 @@ napi_value NapiRootInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
fileInfo.mode = DOCUMENT_FLAG_REPRESENTS_DIR | DOCUMENT_FLAG_SUPPORTS_READ | DOCUMENT_FLAG_SUPPORTS_WRITE;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(fileIteratorEntity->entityOperateMutex);
|
||||
int ret = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("RootInfoList", DEFAULT_CAPACITY_200KB,
|
||||
fileIteratorEntity->memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
fileIteratorEntity->fileAccessHelper = rootEntity->fileAccessHelper;
|
||||
fileIteratorEntity->fileInfo = fileInfo;
|
||||
fileIteratorEntity->fileInfoVec.clear();
|
||||
fileIteratorEntity->offset = 0;
|
||||
fileIteratorEntity->pos = 0;
|
||||
fileIteratorEntity->filter = std::move(filter);
|
||||
fileIteratorEntity->flag = 0;
|
||||
auto ret = rootEntity->fileAccessHelper->ListFile(fileInfo, fileIteratorEntity->offset,
|
||||
MAX_COUNT, filter, fileIteratorEntity->fileInfoVec);
|
||||
fileIteratorEntity->flag = CALL_LISTFILE;
|
||||
ret = rootEntity->fileAccessHelper->ListFile(fileInfo, fileIteratorEntity->offset, filter,
|
||||
fileIteratorEntity->memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(fileIteratorEntity->memInfo);
|
||||
return NapiFileInfoExporter::ThrowError(env, ret);
|
||||
}
|
||||
}
|
||||
@ -170,7 +175,7 @@ napi_value NapiRootInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
fileIteratorEntity->offset = 0;
|
||||
fileIteratorEntity->pos = 0;
|
||||
fileIteratorEntity->filter = std::move(filter);
|
||||
fileIteratorEntity->flag = 1;
|
||||
fileIteratorEntity->flag = CALL_SCANFILE;
|
||||
auto ret = rootEntity->fileAccessHelper->ScanFile(fileInfo, fileIteratorEntity->offset,
|
||||
MAX_COUNT, filter, fileIteratorEntity->fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
|
@ -60,6 +60,7 @@ ohos_shared_library("file_access_extension_ability_kit") {
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
|
||||
"${commonlibrary_path}/c_utils/base/include",
|
||||
"${file_api_path}/utils/filemgmt_libn/include",
|
||||
"${user_file_service_path}/services/native/file_access_service/include",
|
||||
]
|
||||
|
@ -46,8 +46,8 @@ public:
|
||||
virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> ©Result,
|
||||
bool force = false) override;
|
||||
virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) override;
|
||||
virtual int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override;
|
||||
virtual int ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
|
||||
SharedMemoryInfo &memInfo) override;
|
||||
virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override;
|
||||
virtual int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize,
|
||||
|
@ -44,8 +44,8 @@ public:
|
||||
int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> ©Result,
|
||||
bool force = false) override;
|
||||
int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) override;
|
||||
int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override;
|
||||
int ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
|
||||
SharedMemoryInfo &memInfo) override;
|
||||
int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override;
|
||||
int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize, std::shared_ptr<PixelMap> &pixelMap) override;
|
||||
|
@ -78,8 +78,7 @@ public:
|
||||
int Move(Uri &sourceFile, Uri &targetParent, Uri &newFile);
|
||||
int Copy(Uri &sourceUri, Uri &destUri, std::vector<Result> ©Result, bool force = false);
|
||||
int Rename(Uri &sourceFile, const std::string &displayName, Uri &newFile);
|
||||
int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const FileFilter &filter,
|
||||
std::vector<FileInfo> &fileInfoVec);
|
||||
int ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter, SharedMemoryInfo &memInfo);
|
||||
int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const FileFilter &filter,
|
||||
std::vector<FileInfo> &fileInfoVec);
|
||||
int GetThumbnail(Uri &uri, ThumbnailSize &thumbnailSize, std::shared_ptr<PixelMap> &pixelMap);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "file_access_extension_info.h"
|
||||
#include "file_access_framework_errno.h"
|
||||
#include "file_filter.h"
|
||||
#include "file_info_shared_memory.h"
|
||||
#include "image_source.h"
|
||||
#include "uri.h"
|
||||
|
||||
@ -65,8 +66,8 @@ public:
|
||||
virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> ©Result,
|
||||
bool force = false) = 0;
|
||||
virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) = 0;
|
||||
virtual int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) = 0;
|
||||
virtual int ListFile(const FileInfo &fileInfo, const int64_t offset,
|
||||
const FileFilter &filter, SharedMemoryInfo &memInfo) = 0;
|
||||
virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) = 0;
|
||||
virtual int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize,
|
||||
|
@ -460,18 +460,16 @@ static int GetListFileResult(MessageParcel &reply, std::vector<FileInfo> &fileIn
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec)
|
||||
static int WriteFileFilterFuncArguments(MessageParcel &data,
|
||||
std::tuple<const FileInfo *, int64_t, const FileFilter *, SharedMemoryInfo *> args)
|
||||
{
|
||||
UserAccessTracer trace;
|
||||
trace.Start("ListFile");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
return E_IPCS;
|
||||
}
|
||||
const FileInfo *fileInfo;
|
||||
int64_t offset;
|
||||
const FileFilter *filter;
|
||||
SharedMemoryInfo *memInfo;
|
||||
std::tie(fileInfo, offset, filter, memInfo) = args;
|
||||
|
||||
if (!data.WriteParcelable(&fileInfo)) {
|
||||
if (!data.WriteParcelable(fileInfo)) {
|
||||
HILOG_ERROR("fail to WriteParcelable fileInfo");
|
||||
return E_IPCS;
|
||||
}
|
||||
@ -481,15 +479,58 @@ int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset,
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteInt64(maxCount)) {
|
||||
HILOG_ERROR("fail to WriteInt64 maxCount");
|
||||
if (!data.WriteParcelable(filter)) {
|
||||
HILOG_ERROR("fail to WriteParcelable filter");
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&filter)) {
|
||||
HILOG_ERROR("fail to WriteParcelable filter");
|
||||
if (!data.WriteParcelable(memInfo)) {
|
||||
HILOG_ERROR("fail to WriteParcelable memInfo");
|
||||
return E_IPCS;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static int ReadFileFilterResults(MessageParcel &reply, SharedMemoryInfo &memInfo)
|
||||
{
|
||||
if (!reply.ReadUint32(memInfo.dataCounts)) {
|
||||
HILOG_ERROR("fail to ReadUnt64 dataCounts");
|
||||
return E_IPCS;
|
||||
}
|
||||
memInfo.totalDataCounts = memInfo.dataCounts;
|
||||
|
||||
if (!reply.ReadUint64(memInfo.dataSize)) {
|
||||
HILOG_ERROR("fail to ReadUnt64 dataSize");
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.ReadUint32(memInfo.leftDataCounts)) {
|
||||
HILOG_ERROR("fail to ReadUnt64 leftDataCounts");
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.ReadBool(memInfo.isOver)) {
|
||||
HILOG_ERROR("fail to ReadBool isOver");
|
||||
return E_IPCS;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
|
||||
SharedMemoryInfo &memInfo)
|
||||
{
|
||||
UserAccessTracer trace;
|
||||
trace.Start("ListFile");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = WriteFileFilterFuncArguments(data, std::make_tuple(&fileInfo, offset, &filter, &memInfo));
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
@ -498,13 +539,20 @@ int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset,
|
||||
HILOG_ERROR("fail to SendRequest. err: %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = GetListFileResult(reply, fileInfoVec);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("fail to GetListFileResult. err: %{public}d", err);
|
||||
return err;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
return E_IPCS;
|
||||
}
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("ListFile operation failed ret : %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ReadFileFilterResults(reply, memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("fail to read server return results. ret: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -368,57 +368,92 @@ ErrCode FileAccessExtStub::CmdRename(MessageParcel &data, MessageParcel &reply)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode FileAccessExtStub::CmdListFile(MessageParcel &data, MessageParcel &reply)
|
||||
std::tuple<int, std::shared_ptr<FileInfo>, int64_t, std::shared_ptr<FileFilter>, std::shared_ptr<SharedMemoryInfo>>
|
||||
ReadFileFilterFuncArguments(MessageParcel &data)
|
||||
{
|
||||
UserAccessTracer trace;
|
||||
trace.Start("CmdListFile");
|
||||
std::shared_ptr<FileInfo> fileInfo(data.ReadParcelable<FileInfo>());
|
||||
if (fileInfo == nullptr) {
|
||||
HILOG_ERROR("Parameter ListFile fail to ReadParcelable fileInfo");
|
||||
return E_IPCS;
|
||||
return std::make_tuple(E_IPCS, nullptr, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
int64_t offset = 0;
|
||||
if (!data.ReadInt64(offset)) {
|
||||
HILOG_ERROR("parameter ListFile offset is invalid");
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t maxCount = 0;
|
||||
if (!data.ReadInt64(maxCount)) {
|
||||
HILOG_ERROR("parameter ListFile maxCount is invalid");
|
||||
return E_IPCS;
|
||||
return std::make_tuple(E_IPCS, nullptr, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
std::shared_ptr<FileFilter> filter(data.ReadParcelable<FileFilter>());
|
||||
if (filter == nullptr) {
|
||||
HILOG_ERROR("parameter ListFile FileFilter is invalid");
|
||||
return std::make_tuple(E_IPCS, nullptr, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
std::shared_ptr<SharedMemoryInfo> memInfo(data.ReadParcelable<SharedMemoryInfo>());
|
||||
if (memInfo == nullptr) {
|
||||
HILOG_ERROR("parameter ListFile SharedMemoryInfo is invalid");
|
||||
return std::make_tuple(E_IPCS, nullptr, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
return std::make_tuple(ERR_OK, fileInfo, offset, filter, memInfo);
|
||||
}
|
||||
|
||||
int WriteFileFilterResults(MessageParcel &reply, SharedMemoryInfo &memInfo)
|
||||
{
|
||||
if (!reply.WriteUint32(memInfo.dataCounts)) {
|
||||
HILOG_ERROR("fail to WriteUint32 dataCounts");
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
int ret = ListFile(*fileInfo, offset, maxCount, *filter, fileInfoVec);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter ListFile fail to WriteInt32 ret");
|
||||
if (!reply.WriteUint64(memInfo.dataSize)) {
|
||||
HILOG_ERROR("fail to WriteUint32 dataSize");
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t count {fileInfoVec.size()};
|
||||
if (!reply.WriteInt64(count)) {
|
||||
HILOG_ERROR("Parameter ListFile fail to WriteInt64 count");
|
||||
if (!reply.WriteUint32(memInfo.leftDataCounts)) {
|
||||
HILOG_ERROR("fail to WriteUint32 leftDataCounts");
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
for (const auto &fileInfo : fileInfoVec) {
|
||||
if (!reply.WriteParcelable(&fileInfo)) {
|
||||
HILOG_ERROR("parameter ListFile fail to WriteParcelable fileInfoVec");
|
||||
if (!reply.WriteBool(memInfo.isOver)) {
|
||||
HILOG_ERROR("fail to WriteBool isOver");
|
||||
return E_IPCS;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode FileAccessExtStub::CmdListFile(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
UserAccessTracer trace;
|
||||
trace.Start("CmdListFile");
|
||||
int ret = E_IPCS;
|
||||
std::shared_ptr<FileInfo> fileInfo = nullptr;
|
||||
int64_t offset = 0;
|
||||
std::shared_ptr<FileFilter> filter = nullptr;
|
||||
std::shared_ptr<SharedMemoryInfo> memInfo = nullptr;
|
||||
|
||||
std::tie(ret, fileInfo, offset, filter, memInfo) = ReadFileFilterFuncArguments(data);
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
ret = SharedMemoryOperation::MapSharedMemory(*memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ListFile(*fileInfo, offset, *filter, *memInfo);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("ListFile fail to WriteInt32 ret");
|
||||
SharedMemoryOperation::DestroySharedMemory(*memInfo);
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
ret = WriteFileFilterResults(reply, *memInfo);
|
||||
SharedMemoryOperation::DestroySharedMemory(*memInfo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ErrCode FileAccessExtStub::CmdScanFile(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
UserAccessTracer trace;
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace FileAccessFwk {
|
||||
const int64_t FILEFILTER_DEFAULT_COUNTS = 2000;
|
||||
const int64_t FILEFILTER_MAX_COUNTS = 20000;
|
||||
std::shared_ptr<FileAccessExtAbility> FileAccessExtStubImpl::GetOwner()
|
||||
{
|
||||
return extension_;
|
||||
@ -119,8 +121,8 @@ int FileAccessExtStubImpl::Rename(const Uri &sourceFile, const std::string &disp
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec)
|
||||
int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
|
||||
SharedMemoryInfo &memInfo)
|
||||
{
|
||||
UserAccessTracer trace;
|
||||
trace.Start("ListFile");
|
||||
@ -129,7 +131,36 @@ int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offs
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
int ret = ERR_OK;
|
||||
memInfo.isOver = false;
|
||||
int64_t currentOffset = offset;
|
||||
while (true) {
|
||||
int64_t maxCounts =
|
||||
memInfo.memSize > DEFAULT_CAPACITY_200KB ? FILEFILTER_MAX_COUNTS : FILEFILTER_DEFAULT_COUNTS;
|
||||
fileInfoVec.clear();
|
||||
ret = extension_->ListFile(fileInfo, currentOffset, maxCounts, filter, fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("Extension ability ListFile error, code:%{public}d", ret);
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t currentWriteCounts = SharedMemoryOperation::WriteFileInfos(fileInfoVec, memInfo);
|
||||
if (currentWriteCounts < fileInfoVec.size()) {
|
||||
if (memInfo.memSize == DEFAULT_CAPACITY_200KB) {
|
||||
uint32_t counts = 0;
|
||||
extension_->GetFileInfoNum(fileInfo.uri, filter, false, counts);
|
||||
memInfo.leftDataCounts = counts - memInfo.dataCounts;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (fileInfoVec.empty() ||(maxCounts > fileInfoVec.size() && currentWriteCounts == fileInfoVec.size())) {
|
||||
memInfo.isOver = true;
|
||||
break;
|
||||
}
|
||||
currentOffset += currentWriteCounts;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -746,8 +746,8 @@ int FileAccessHelper::Rename(Uri &sourceFile, const std::string &displayName, Ur
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec)
|
||||
int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
|
||||
SharedMemoryInfo &memInfo)
|
||||
{
|
||||
UserAccessTracer trace;
|
||||
trace.Start("ListFile");
|
||||
@ -768,12 +768,12 @@ int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, c
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
memInfo.Clear();
|
||||
int ret = fileExtProxy->ListFile(fileInfo, offset, filter, memInfo);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("ListFile get result error, code:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FILE_INFO_SHARED_MEMORY_H
|
||||
#define FILE_INFO_SHARED_MEMORY_H
|
||||
#ifndef _FILE_INFO_SHARED_MEMORY_H_
|
||||
#define _FILE_INFO_SHARED_MEMORY_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
@ -398,4 +398,4 @@ private:
|
||||
};
|
||||
} // namespace FileAccessFwk
|
||||
} // namespace OHOS
|
||||
#endif // FILE_INFO_SHARED_MEMORY_H
|
||||
#endif // _FILE_INFO_SHARED_MEMORY_H_
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "nativetoken_kit.h"
|
||||
#include "file_access_framework_errno.h"
|
||||
#include "file_access_helper.h"
|
||||
#include "file_info_shared_memory.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
@ -370,10 +371,12 @@ bool ListFileFuzzTest(const uint8_t* data, size_t size)
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = std::string(reinterpret_cast<const char*>(data), size);
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
SharedMemoryInfo memInfo;
|
||||
int result = SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
FileFilter filter;
|
||||
int result = helper->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
result = helper->ListFile(fileInfo, offset, filter, memInfo);
|
||||
SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
if (result != OHOS::FileAccessFwk::ERR_OK) {
|
||||
HILOG_ERROR("ListFile failed. ret : %{public}d", result);
|
||||
return false;
|
||||
|
@ -288,11 +288,13 @@ HWTEST_F(AbnormalFileExtensionHelperTest, abnormal_external_file_access_ListFile
|
||||
try {
|
||||
FileInfo fileInfo;
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 0;
|
||||
FileFilter filter;
|
||||
vector<FileInfo> fileInfoVec;
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
SharedMemoryInfo memInfo;
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, E_PERMISSION_SYS);
|
||||
SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "abnormal_external_file_access_ListFile_0000 occurs an exception.";
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "accesstoken_kit.h"
|
||||
#include "context_impl.h"
|
||||
#include "file_access_framework_errno.h"
|
||||
#include "file_info_shared_memory.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
@ -3046,14 +3047,16 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0000, testing::e
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = newDirUriTest.ToString();
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter;
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
SharedMemoryInfo memInfo;
|
||||
result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GT(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GT(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0000 occurs an exception.";
|
||||
@ -3078,12 +3081,14 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0001, testing::e
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = sourceFileUri.ToString();
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter;
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
SharedMemoryInfo memInfo;
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0001 occurs an exception.";
|
||||
}
|
||||
@ -3119,14 +3124,16 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0002, testing::e
|
||||
fileInfo.uri = sourceFileUri.ToString();
|
||||
Uri sourceFile(fileInfo.uri);
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter;
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
SharedMemoryInfo memInfo;
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0002 occurs an exception.";
|
||||
@ -3152,23 +3159,25 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0003, testing::e
|
||||
fileInfo.uri = sourceFileUri.ToString();
|
||||
Uri sourceFile(fileInfo.uri);
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter;
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
SharedMemoryInfo memInfo;
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0003 occurs an exception.";
|
||||
}
|
||||
GTEST_LOG_(INFO) << "FileExtensionHelperTest-end external_file_access_ListFile_0003";
|
||||
}
|
||||
|
||||
static void ListFileTdd(FileInfo fileInfo, int offset, int maxCount, FileFilter filter,
|
||||
std::vector<FileInfo> fileInfoVec)
|
||||
static void ListFileTdd(FileInfo fileInfo, int offset, FileFilter filter,
|
||||
SharedMemoryInfo &memInfo)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "FileExtensionHelperTest-begin external_file_access_ListFileTdd";
|
||||
int ret = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
int ret = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
if (ret != OHOS::FileAccessFwk::ERR_OK) {
|
||||
GTEST_LOG_(ERROR) << "ListFile get result error, code:" << ret;
|
||||
return;
|
||||
@ -3205,17 +3214,19 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0004, testing::e
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = newDirUriTest.ToString();
|
||||
int offset = 0;
|
||||
int maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter;
|
||||
g_num = 0;
|
||||
SharedMemoryInfo memInfo;
|
||||
result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
for (int j = 0; j < INIT_THREADS_NUMBER; j++) {
|
||||
std::thread execthread(ListFileTdd, fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
std::thread execthread(ListFileTdd, fileInfo, offset, filter, std::ref(memInfo));
|
||||
execthread.join();
|
||||
}
|
||||
EXPECT_EQ(g_num, INIT_THREADS_NUMBER);
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0004 occurs an exception.";
|
||||
@ -3256,13 +3267,15 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0005, testing::e
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = str;
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter;
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
SharedMemoryInfo memInfo;
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0005 occurs an exception.";
|
||||
@ -3299,14 +3312,16 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0006, testing::e
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = newDirUriTest.ToString();
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter;
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
SharedMemoryInfo memInfo;
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GT(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GT(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0006 occurs an exception.";
|
||||
@ -3314,7 +3329,6 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0006, testing::e
|
||||
GTEST_LOG_(INFO) << "FileExtensionHelperTest-end external_file_access_ListFile_0006";
|
||||
}
|
||||
|
||||
|
||||
static void WriteData(Uri &uri)
|
||||
{
|
||||
int fd = -1;
|
||||
@ -3365,12 +3379,14 @@ static void ListFileFilter7(Uri newDirUriTest)
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = newDirUriTest.ToString();
|
||||
int64_t offset = 4;
|
||||
int64_t maxCount = 1;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
SharedMemoryInfo memInfo;
|
||||
FileFilter filter({".txt", ".docx"}, {}, {}, -1, -1, false, true);
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_1);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_1);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3417,9 +3433,11 @@ static double InitListFileFolder(Uri newDirUriTest, const std::string &caseNumbe
|
||||
return time;
|
||||
}
|
||||
|
||||
static void ShowInfo(const std::vector<FileInfo> &fileInfoVec, const std::string &caseNumber)
|
||||
static void ShowInfo(SharedMemoryInfo &memInfo, const std::string &caseNumber)
|
||||
{
|
||||
for (auto fileInfo : fileInfoVec) {
|
||||
FileAccessFwk::FileInfo fileInfo;
|
||||
for (size_t i = 0; i < memInfo.Size(); i++) {
|
||||
FileAccessFwk::SharedMemoryOperation::ReadFileInfo(fileInfo, memInfo);
|
||||
GTEST_LOG_(INFO) << caseNumber << ", uri:" << fileInfo.uri << endl;
|
||||
}
|
||||
}
|
||||
@ -3429,13 +3447,15 @@ static void ListFileFilter8(Uri newDirUriTest)
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = newDirUriTest.ToString();
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
SharedMemoryInfo memInfo;
|
||||
FileFilter filter({}, {}, {}, -1, 0, false, true);
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_6);
|
||||
ShowInfo(fileInfoVec, "external_file_access_ListFile_0008");
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_6);
|
||||
ShowInfo(memInfo, "external_file_access_ListFile_0008");
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3475,12 +3495,14 @@ static void ListFileFilter9(Uri newDirUriTest)
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = newDirUriTest.ToString();
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
SharedMemoryInfo memInfo;
|
||||
FileFilter filter;
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_6);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_6);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3520,33 +3542,35 @@ static void ListFileFilter10(Uri newDirUriTest, const double &time)
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = newDirUriTest.ToString();
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
SharedMemoryInfo memInfo;
|
||||
FileFilter filter({".txt", ".docx"}, {}, {}, -1, -1, false, true);
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_5);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_5);
|
||||
|
||||
FileFilter filter1({".txt", ".docx"}, {"0010.txt", "0010.docx"}, {}, -1, -1, false, true);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter1, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter1, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_4);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_4);
|
||||
|
||||
FileFilter filter2({".txt", ".docx"}, {"0010.txt", "0010.docx"}, {}, 0, 0, false, true);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter2, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter2, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_1);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_1);
|
||||
|
||||
FileFilter filter3({".txt", ".docx"}, {"0010.txt", "0010.docx"}, {}, -1, time, false, true);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter3, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter3, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_2);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_2);
|
||||
|
||||
double nowTime = GetTime();
|
||||
FileFilter filter4({".txt", ".docx"}, {"0010.txt", "0010.docx"}, {}, -1, nowTime, false, true);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter4, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter4, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), 0);
|
||||
EXPECT_EQ(memInfo.Size(), 0);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3586,33 +3610,35 @@ static void ListFileFilter11(Uri newDirUriTest, const double &time)
|
||||
FileInfo fileInfo;
|
||||
fileInfo.uri = newDirUriTest.ToString();
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
SharedMemoryInfo memInfo;
|
||||
int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
FileFilter filter({".txt", ".docx"}, {}, {}, -1, -1, false, true);
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_6);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_6);
|
||||
|
||||
FileFilter filter1({".txt", ".docx"}, {"测试.txt", "测试.docx"}, {}, -1, -1, false, true);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter1, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter1, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_4);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_4);
|
||||
|
||||
FileFilter filter2({".txt", ".docx"}, {"测试.txt", "测试.docx"}, {}, 0, 0, false, true);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter2, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter2, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_1);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_1);
|
||||
|
||||
FileFilter filter3({".txt", ".docx"}, {"测试.txt", "测试.docx"}, {}, -1, time, false, true);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter3, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter3, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_2);
|
||||
EXPECT_EQ(memInfo.Size(), FILE_COUNT_2);
|
||||
|
||||
double nowTime = GetTime();
|
||||
FileFilter filter4({".txt", ".docx"}, {"测试.txt", "测试.docx"}, {}, -1, nowTime, false, true);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter4, fileInfoVec);
|
||||
result = g_fah->ListFile(fileInfo, offset, filter4, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), 0);
|
||||
EXPECT_EQ(memInfo.Size(), 0);
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4140,6 +4166,9 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0000,
|
||||
vector<RootInfo> info;
|
||||
int result = g_fah->GetRoots(info);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
SharedMemoryInfo memInfo;
|
||||
result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
for (size_t i = 0; i < info.size(); i++) {
|
||||
Uri parentUri(info[i].uri);
|
||||
FileInfo fileinfo;
|
||||
@ -4147,13 +4176,12 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0000,
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
FileFilter filter;
|
||||
std::vector<FileInfo> fileInfoVecTemp;
|
||||
result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp);
|
||||
result = g_fah->ListFile(fileinfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GE(fileInfoVecTemp.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GE(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
}
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0000 occurs an exception.";
|
||||
}
|
||||
@ -4177,6 +4205,9 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0001,
|
||||
vector<RootInfo> info;
|
||||
int result = g_fah->GetRoots(info);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
SharedMemoryInfo memInfo;
|
||||
result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
for (size_t i = 0; i < info.size(); i++) {
|
||||
Uri parentUri(info[i].uri);
|
||||
Uri newDirUriTest("");
|
||||
@ -4188,16 +4219,15 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0001,
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
FileFilter filter;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
result = g_fah->ListFile(dirInfo, offset, maxCount, filter, fileInfoVec);
|
||||
result = g_fah->ListFile(dirInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GE(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GE(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
}
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0001 occurs an exception.";
|
||||
}
|
||||
@ -4221,6 +4251,9 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0002,
|
||||
vector<RootInfo> info;
|
||||
int result = g_fah->GetRoots(info);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
SharedMemoryInfo memInfo;
|
||||
result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
for (size_t i = 0; i < info.size(); i++) {
|
||||
Uri parentUri(info[i].uri);
|
||||
Uri newDirUriTest("");
|
||||
@ -4235,16 +4268,15 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0002,
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
FileFilter filter;
|
||||
std::vector<FileInfo> fileInfoVecTemp;
|
||||
result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp);
|
||||
result = g_fah->ListFile(fileinfo, offset, filter, memInfo);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVecTemp.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
}
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0002 occurs an exception.";
|
||||
}
|
||||
@ -4363,6 +4395,9 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0006,
|
||||
vector<RootInfo> info;
|
||||
int result = g_fah->GetRoots(info);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
SharedMemoryInfo memInfo;
|
||||
result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
for (size_t i = 0; i < info.size(); i++) {
|
||||
Uri parentUri(info[i].uri);
|
||||
Uri newDirUriTest("");
|
||||
@ -4375,16 +4410,15 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0006,
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
FileFilter filter;
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
result = g_fah->ListFile(dirInfo, offset, maxCount, filter, fileInfoVec);
|
||||
result = g_fah->ListFile(dirInfo, offset, filter, memInfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GE(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_GE(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
}
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0006 occurs an exception.";
|
||||
}
|
||||
@ -4408,6 +4442,9 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0007,
|
||||
vector<RootInfo> info;
|
||||
int result = g_fah->GetRoots(info);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
SharedMemoryInfo memInfo;
|
||||
result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
|
||||
memInfo);
|
||||
for (size_t i = 0; i < info.size(); i++) {
|
||||
Uri parentUri(info[i].uri);
|
||||
Uri newDirUriTest("");
|
||||
@ -4424,16 +4461,16 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0007,
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
int64_t offset = 0;
|
||||
int64_t maxCount = 1000;
|
||||
FileFilter filter;
|
||||
std::vector<FileInfo> fileInfoVecTemp;
|
||||
result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp);
|
||||
result = g_fah->ListFile(fileinfo, offset, filter, memInfo);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVecTemp.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(memInfo.Size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
}
|
||||
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0007 occurs an exception.";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user