feat: implement listFile interface based on shared memory

Signed-off-by: caochuan <caochuan@huawei.com>
This commit is contained in:
caochuan 2023-11-21 16:46:58 +08:00
parent c07db6d631
commit 14745d21d5
18 changed files with 406 additions and 193 deletions

View File

@ -20,3 +20,4 @@ access_token_path = "//base/security/access_token"
file_api_path = "//foundation/filemanagement/file_api" file_api_path = "//foundation/filemanagement/file_api"
user_file_service_path = "//foundation/filemanagement/user_file_service" user_file_service_path = "//foundation/filemanagement/user_file_service"
distributed_file_path = "//foundation/distributeddatamgr/distributedfile" distributed_file_path = "//foundation/distributeddatamgr/distributedfile"
commonlibrary_path = "//commonlibrary"

View File

@ -22,21 +22,29 @@
#include "file_access_helper.h" #include "file_access_helper.h"
#include "hilog_wrapper.h" #include "hilog_wrapper.h"
#include "file_filter.h" #include "file_filter.h"
#include "file_info_shared_memory.h"
namespace OHOS { namespace OHOS {
namespace FileAccessFwk { namespace FileAccessFwk {
constexpr int64_t MAX_COUNT = 200; // ListFile get file's max count constexpr int64_t MAX_COUNT = 200; // ListFile get file's max count
constexpr int CALL_LISTFILE = 0;
constexpr int CALL_SCANFILE = 1;
struct FileIteratorEntity { struct FileIteratorEntity {
~FileIteratorEntity() {
SharedMemoryOperation::DestroySharedMemory(memInfo);
}
FileAccessHelper *fileAccessHelper { nullptr }; FileAccessHelper *fileAccessHelper { nullptr };
std::mutex entityOperateMutex; std::mutex entityOperateMutex;
FileInfo fileInfo; FileInfo fileInfo;
std::vector<FileInfo> fileInfoVec; std::vector<FileInfo> fileInfoVec;
SharedMemoryInfo memInfo;
int64_t offset { 0 }; int64_t offset { 0 };
uint64_t pos { 0 }; uint64_t pos { 0 };
uint32_t currentDataCounts { 0 };
FileFilter filter { {}, {}, {}, FileFilter::INVALID_SIZE, FileFilter::INVALID_MODIFY_AFTER, false, false }; FileFilter filter { {}, {}, {}, FileFilter::INVALID_SIZE, FileFilter::INVALID_MODIFY_AFTER, false, false };
int flag { 0 }; int flag { CALL_LISTFILE };
}; };
} // namespace FileAccessFwk } // namespace FileAccessFwk
} // namespace OHOS } // namespace OHOS

View File

@ -119,18 +119,25 @@ napi_value NapiFileInfoExporter::ListFile(napi_env env, napi_callback_info info)
} }
{ {
std::lock_guard<std::mutex> lock(fileIteratorEntity->entityOperateMutex); 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->fileAccessHelper = fileInfoEntity->fileAccessHelper;
fileIteratorEntity->fileInfo = fileInfoEntity->fileInfo; fileIteratorEntity->fileInfo = fileInfoEntity->fileInfo;
fileIteratorEntity->fileInfoVec.clear();
fileIteratorEntity->offset = 0; fileIteratorEntity->offset = 0;
fileIteratorEntity->pos = 0;
fileIteratorEntity->filter = std::move(filter); fileIteratorEntity->filter = std::move(filter);
fileIteratorEntity->flag = 0; fileIteratorEntity->flag = CALL_LISTFILE;
auto ret = fileInfoEntity->fileAccessHelper->ListFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset, ret = fileInfoEntity->fileAccessHelper->ListFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset,
MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec); fileIteratorEntity->filter, fileIteratorEntity->memInfo);
if (ret != ERR_OK) { if (ret != ERR_OK) {
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(fileIteratorEntity->memInfo);
return ThrowError(env, ret); return ThrowError(env, ret);
} }
fileIteratorEntity->currentDataCounts = fileIteratorEntity->memInfo.totalDataCounts;
} }
return NVal(env, objFileIteratorExporter).val_; 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->fileInfo = fileInfoEntity->fileInfo;
fileIteratorEntity->fileInfoVec.clear(); fileIteratorEntity->fileInfoVec.clear();
fileIteratorEntity->offset = 0; fileIteratorEntity->offset = 0;
fileIteratorEntity->pos = 0;
fileIteratorEntity->filter = std::move(filter); fileIteratorEntity->filter = std::move(filter);
fileIteratorEntity->flag = 1; fileIteratorEntity->flag = CALL_SCANFILE;
auto ret = fileInfoEntity->fileAccessHelper->ScanFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset, auto ret = fileInfoEntity->fileAccessHelper->ScanFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset,
MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec); MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec);
if (ret != ERR_OK) { if (ret != ERR_OK) {
@ -284,4 +290,4 @@ std::string NapiFileInfoExporter::GetClassName()
return NapiFileInfoExporter::className_; return NapiFileInfoExporter::className_;
} }
} // namespace FileAccessFwk } // namespace FileAccessFwk
} // namespace OHOS } // namespace OHOS

View File

@ -74,7 +74,44 @@ napi_value NapiFileIteratorExporter::Constructor(napi_env env, napi_callback_inf
return funcArg.GetThisVar(); 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) FileInfoEntity *fileInfoEntity, napi_env env, NVal &nVal, bool &isDone)
{ {
std::lock_guard<std::mutex> lock(fileIteratorEntity->entityOperateMutex); std::lock_guard<std::mutex> lock(fileIteratorEntity->entityOperateMutex);
@ -93,20 +130,11 @@ static int MakeResult(napi_value &objFileInfoExporter, FileIteratorEntity *fileI
fileIteratorEntity->fileInfoVec.clear(); fileIteratorEntity->fileInfoVec.clear();
fileIteratorEntity->offset += MAX_COUNT; fileIteratorEntity->offset += MAX_COUNT;
fileIteratorEntity->pos = 0; fileIteratorEntity->pos = 0;
if (fileIteratorEntity->flag == 0) { int ret = fileIteratorEntity->fileAccessHelper->ScanFile(fileIteratorEntity->fileInfo,
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); fileIteratorEntity->offset, MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec);
if (ret != ERR_OK) { if (ret != ERR_OK) {
HILOG_ERROR("exec ScanFile fail, code:%{public}d", ret); HILOG_ERROR("exec ScanFile fail, code:%{public}d", ret);
return ret; return ret;
}
} }
} }
if (fileIteratorEntity->pos == fileIteratorEntity->fileInfoVec.size()) { if (fileIteratorEntity->pos == fileIteratorEntity->fileInfoVec.size()) {
@ -174,20 +202,28 @@ napi_value NapiFileIteratorExporter::Next(napi_env env, napi_callback_info info)
} }
auto retNVal = NVal::CreateObject(env); auto retNVal = NVal::CreateObject(env);
int ret = E_GETRESULT;
bool isDone = false; 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)) { while (!isDone && FilterTrashAndRecentDir(fileInfoEntity->fileInfo.uri)) {
fileInfoEntity = NClass::GetEntityOf<FileInfoEntity>(env, objFileInfoExporter); fileInfoEntity = NClass::GetEntityOf<FileInfoEntity>(env, objFileInfoExporter);
retNVal = NVal::CreateObject(env); retNVal = NVal::CreateObject(env);
HILOG_DEBUG("TRASH_DIR or RECENT_DIR: %{public}s", fileInfoEntity->fileInfo.uri.c_str()); 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) { if (ret != ERR_OK) {
NError(ret).ThrowErr(env); NError(ret).ThrowErr(env);
return nullptr; return nullptr;
} }
return retNVal.val_; return retNVal.val_;
} }

View File

@ -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; fileInfo.mode = DOCUMENT_FLAG_REPRESENTS_DIR | DOCUMENT_FLAG_SUPPORTS_READ | DOCUMENT_FLAG_SUPPORTS_WRITE;
{ {
std::lock_guard<std::mutex> lock(fileIteratorEntity->entityOperateMutex); 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->fileAccessHelper = rootEntity->fileAccessHelper;
fileIteratorEntity->fileInfo = fileInfo; fileIteratorEntity->fileInfo = fileInfo;
fileIteratorEntity->fileInfoVec.clear();
fileIteratorEntity->offset = 0; fileIteratorEntity->offset = 0;
fileIteratorEntity->pos = 0;
fileIteratorEntity->filter = std::move(filter); fileIteratorEntity->filter = std::move(filter);
fileIteratorEntity->flag = 0; fileIteratorEntity->flag = CALL_LISTFILE;
auto ret = rootEntity->fileAccessHelper->ListFile(fileInfo, fileIteratorEntity->offset, ret = rootEntity->fileAccessHelper->ListFile(fileInfo, fileIteratorEntity->offset, filter,
MAX_COUNT, filter, fileIteratorEntity->fileInfoVec); fileIteratorEntity->memInfo);
if (ret != ERR_OK) { if (ret != ERR_OK) {
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(fileIteratorEntity->memInfo);
return NapiFileInfoExporter::ThrowError(env, ret); return NapiFileInfoExporter::ThrowError(env, ret);
} }
} }
@ -170,7 +175,7 @@ napi_value NapiRootInfoExporter::ScanFile(napi_env env, napi_callback_info info)
fileIteratorEntity->offset = 0; fileIteratorEntity->offset = 0;
fileIteratorEntity->pos = 0; fileIteratorEntity->pos = 0;
fileIteratorEntity->filter = std::move(filter); fileIteratorEntity->filter = std::move(filter);
fileIteratorEntity->flag = 1; fileIteratorEntity->flag = CALL_SCANFILE;
auto ret = rootEntity->fileAccessHelper->ScanFile(fileInfo, fileIteratorEntity->offset, auto ret = rootEntity->fileAccessHelper->ScanFile(fileInfo, fileIteratorEntity->offset,
MAX_COUNT, filter, fileIteratorEntity->fileInfoVec); MAX_COUNT, filter, fileIteratorEntity->fileInfoVec);
if (ret != ERR_OK) { if (ret != ERR_OK) {
@ -271,4 +276,4 @@ std::string NapiRootInfoExporter::GetClassName()
} }
} // namespace FileAccessFwk } // namespace FileAccessFwk
} // namespace OHOS } // namespace OHOS
#endif // NAPI_FILEACCESS_HELPER_H #endif // NAPI_FILEACCESS_HELPER_H

View File

@ -60,6 +60,7 @@ ohos_shared_library("file_access_extension_ability_kit") {
include_dirs = [ include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${commonlibrary_path}/c_utils/base/include",
"${file_api_path}/utils/filemgmt_libn/include", "${file_api_path}/utils/filemgmt_libn/include",
"${user_file_service_path}/services/native/file_access_service/include", "${user_file_service_path}/services/native/file_access_service/include",
] ]

View File

@ -46,8 +46,8 @@ public:
virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> &copyResult, virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> &copyResult,
bool force = false) override; bool force = false) override;
virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) 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, virtual int ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override; SharedMemoryInfo &memInfo) override;
virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override; const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override;
virtual int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize, virtual int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize,

View File

@ -44,8 +44,8 @@ public:
int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> &copyResult, int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> &copyResult,
bool force = false) override; bool force = false) override;
int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) 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, int ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override; SharedMemoryInfo &memInfo) override;
int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override; const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override;
int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize, std::shared_ptr<PixelMap> &pixelMap) override; int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize, std::shared_ptr<PixelMap> &pixelMap) override;

View File

@ -78,8 +78,7 @@ public:
int Move(Uri &sourceFile, Uri &targetParent, Uri &newFile); int Move(Uri &sourceFile, Uri &targetParent, Uri &newFile);
int Copy(Uri &sourceUri, Uri &destUri, std::vector<Result> &copyResult, bool force = false); int Copy(Uri &sourceUri, Uri &destUri, std::vector<Result> &copyResult, bool force = false);
int Rename(Uri &sourceFile, const std::string &displayName, Uri &newFile); 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, int ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter, SharedMemoryInfo &memInfo);
std::vector<FileInfo> &fileInfoVec);
int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const FileFilter &filter, int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const FileFilter &filter,
std::vector<FileInfo> &fileInfoVec); std::vector<FileInfo> &fileInfoVec);
int GetThumbnail(Uri &uri, ThumbnailSize &thumbnailSize, std::shared_ptr<PixelMap> &pixelMap); int GetThumbnail(Uri &uri, ThumbnailSize &thumbnailSize, std::shared_ptr<PixelMap> &pixelMap);

View File

@ -24,6 +24,7 @@
#include "file_access_extension_info.h" #include "file_access_extension_info.h"
#include "file_access_framework_errno.h" #include "file_access_framework_errno.h"
#include "file_filter.h" #include "file_filter.h"
#include "file_info_shared_memory.h"
#include "image_source.h" #include "image_source.h"
#include "uri.h" #include "uri.h"
@ -65,8 +66,8 @@ public:
virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> &copyResult, virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> &copyResult,
bool force = false) = 0; bool force = false) = 0;
virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) = 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, virtual int ListFile(const FileInfo &fileInfo, const int64_t offset,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) = 0; const FileFilter &filter, SharedMemoryInfo &memInfo) = 0;
virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) = 0; const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) = 0;
virtual int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize, virtual int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize,

View File

@ -460,18 +460,16 @@ static int GetListFileResult(MessageParcel &reply, std::vector<FileInfo> &fileIn
return ERR_OK; return ERR_OK;
} }
int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, static int WriteFileFilterFuncArguments(MessageParcel &data,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) std::tuple<const FileInfo *, int64_t, const FileFilter *, SharedMemoryInfo *> args)
{ {
UserAccessTracer trace; const FileInfo *fileInfo;
trace.Start("ListFile"); int64_t offset;
MessageParcel data; const FileFilter *filter;
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) { SharedMemoryInfo *memInfo;
HILOG_ERROR("WriteInterfaceToken failed"); std::tie(fileInfo, offset, filter, memInfo) = args;
return E_IPCS;
}
if (!data.WriteParcelable(&fileInfo)) { if (!data.WriteParcelable(fileInfo)) {
HILOG_ERROR("fail to WriteParcelable fileInfo"); HILOG_ERROR("fail to WriteParcelable fileInfo");
return E_IPCS; return E_IPCS;
} }
@ -481,15 +479,58 @@ int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset,
return E_IPCS; return E_IPCS;
} }
if (!data.WriteInt64(maxCount)) { if (!data.WriteParcelable(filter)) {
HILOG_ERROR("fail to WriteInt64 maxCount"); HILOG_ERROR("fail to WriteParcelable filter");
return E_IPCS; return E_IPCS;
} }
if (!data.WriteParcelable(&filter)) { if (!data.WriteParcelable(memInfo)) {
HILOG_ERROR("fail to WriteParcelable filter"); HILOG_ERROR("fail to WriteParcelable memInfo");
return E_IPCS; 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; MessageParcel reply;
MessageOption option; 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); HILOG_ERROR("fail to SendRequest. err: %{public}d", err);
return err; return err;
} }
if (!reply.ReadInt32(ret)) {
err = GetListFileResult(reply, fileInfoVec); HILOG_ERROR("fail to ReadInt32 ret");
if (err != ERR_OK) { return E_IPCS;
HILOG_ERROR("fail to GetListFileResult. err: %{public}d", err); }
return err; 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; return ERR_OK;
} }
@ -1092,4 +1140,4 @@ int FileAccessExtProxy::MoveFile(const Uri &sourceFile, const Uri &targetParent,
return ERR_OK; return ERR_OK;
} }
} // namespace FileAccessFwk } // namespace FileAccessFwk
} // namespace OHOS } // namespace OHOS

View File

@ -368,57 +368,92 @@ ErrCode FileAccessExtStub::CmdRename(MessageParcel &data, MessageParcel &reply)
return ERR_OK; 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>()); std::shared_ptr<FileInfo> fileInfo(data.ReadParcelable<FileInfo>());
if (fileInfo == nullptr) { if (fileInfo == nullptr) {
HILOG_ERROR("Parameter ListFile fail to ReadParcelable fileInfo"); 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; int64_t offset = 0;
if (!data.ReadInt64(offset)) { if (!data.ReadInt64(offset)) {
HILOG_ERROR("parameter ListFile offset is invalid"); HILOG_ERROR("parameter ListFile offset is invalid");
return E_IPCS; return std::make_tuple(E_IPCS, nullptr, 0, nullptr, nullptr);
}
int64_t maxCount = 0;
if (!data.ReadInt64(maxCount)) {
HILOG_ERROR("parameter ListFile maxCount is invalid");
return E_IPCS;
} }
std::shared_ptr<FileFilter> filter(data.ReadParcelable<FileFilter>()); std::shared_ptr<FileFilter> filter(data.ReadParcelable<FileFilter>());
if (filter == nullptr) { if (filter == nullptr) {
HILOG_ERROR("parameter ListFile FileFilter is invalid"); 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; return E_IPCS;
} }
std::vector<FileInfo> fileInfoVec; if (!reply.WriteUint64(memInfo.dataSize)) {
int ret = ListFile(*fileInfo, offset, maxCount, *filter, fileInfoVec); HILOG_ERROR("fail to WriteUint32 dataSize");
if (!reply.WriteInt32(ret)) {
HILOG_ERROR("Parameter ListFile fail to WriteInt32 ret");
return E_IPCS; return E_IPCS;
} }
int64_t count {fileInfoVec.size()}; if (!reply.WriteUint32(memInfo.leftDataCounts)) {
if (!reply.WriteInt64(count)) { HILOG_ERROR("fail to WriteUint32 leftDataCounts");
HILOG_ERROR("Parameter ListFile fail to WriteInt64 count");
return E_IPCS; return E_IPCS;
} }
for (const auto &fileInfo : fileInfoVec) { if (!reply.WriteBool(memInfo.isOver)) {
if (!reply.WriteParcelable(&fileInfo)) { HILOG_ERROR("fail to WriteBool isOver");
HILOG_ERROR("parameter ListFile fail to WriteParcelable fileInfoVec"); return E_IPCS;
return E_IPCS;
}
} }
return ERR_OK; 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) ErrCode FileAccessExtStub::CmdScanFile(MessageParcel &data, MessageParcel &reply)
{ {
UserAccessTracer trace; UserAccessTracer trace;
@ -805,4 +840,4 @@ ErrCode FileAccessExtStub::CmdMoveFile(MessageParcel &data, MessageParcel &reply
return ERR_OK; return ERR_OK;
} }
} // namespace FileAccessFwk } // namespace FileAccessFwk
} // namespace OHOS } // namespace OHOS

View File

@ -23,6 +23,8 @@
namespace OHOS { namespace OHOS {
namespace FileAccessFwk { namespace FileAccessFwk {
const int64_t FILEFILTER_DEFAULT_COUNTS = 2000;
const int64_t FILEFILTER_MAX_COUNTS = 20000;
std::shared_ptr<FileAccessExtAbility> FileAccessExtStubImpl::GetOwner() std::shared_ptr<FileAccessExtAbility> FileAccessExtStubImpl::GetOwner()
{ {
return extension_; return extension_;
@ -119,8 +121,8 @@ int FileAccessExtStubImpl::Rename(const Uri &sourceFile, const std::string &disp
return ret; return ret;
} }
int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) SharedMemoryInfo &memInfo)
{ {
UserAccessTracer trace; UserAccessTracer trace;
trace.Start("ListFile"); trace.Start("ListFile");
@ -129,7 +131,36 @@ int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offs
return E_IPCS; 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; return ret;
} }
@ -283,4 +314,4 @@ int FileAccessExtStubImpl::MoveFile(const Uri &sourceFile, const Uri &targetPare
return extension_->MoveFile(sourceFile, targetParent, fileName, newFile); return extension_->MoveFile(sourceFile, targetParent, fileName, newFile);
} }
} // namespace FileAccessFwk } // namespace FileAccessFwk
} // namespace OHOS } // namespace OHOS

View File

@ -746,8 +746,8 @@ int FileAccessHelper::Rename(Uri &sourceFile, const std::string &displayName, Ur
return ERR_OK; return ERR_OK;
} }
int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) SharedMemoryInfo &memInfo)
{ {
UserAccessTracer trace; UserAccessTracer trace;
trace.Start("ListFile"); trace.Start("ListFile");
@ -768,12 +768,12 @@ int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, c
return E_IPCS; 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) { if (ret != ERR_OK) {
HILOG_ERROR("ListFile get result error, code:%{public}d", ret); HILOG_ERROR("ListFile get result error, code:%{public}d", ret);
return ret; return ret;
} }
return ERR_OK; return ERR_OK;
} }

View File

@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef FILE_INFO_SHARED_MEMORY_H #ifndef _FILE_INFO_SHARED_MEMORY_H_
#define FILE_INFO_SHARED_MEMORY_H #define _FILE_INFO_SHARED_MEMORY_H_
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h> #include <stdint.h>
@ -398,4 +398,4 @@ private:
}; };
} // namespace FileAccessFwk } // namespace FileAccessFwk
} // namespace OHOS } // namespace OHOS
#endif // FILE_INFO_SHARED_MEMORY_H #endif // _FILE_INFO_SHARED_MEMORY_H_

View File

@ -24,6 +24,7 @@
#include "nativetoken_kit.h" #include "nativetoken_kit.h"
#include "file_access_framework_errno.h" #include "file_access_framework_errno.h"
#include "file_access_helper.h" #include "file_access_helper.h"
#include "file_info_shared_memory.h"
#include "iservice_registry.h" #include "iservice_registry.h"
#include "hilog_wrapper.h" #include "hilog_wrapper.h"
@ -370,10 +371,12 @@ bool ListFileFuzzTest(const uint8_t* data, size_t size)
FileInfo fileInfo; FileInfo fileInfo;
fileInfo.uri = std::string(reinterpret_cast<const char*>(data), size); fileInfo.uri = std::string(reinterpret_cast<const char*>(data), size);
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000; SharedMemoryInfo memInfo;
std::vector<FileInfo> fileInfoVec; int result = SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
memInfo);
FileFilter filter; 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) { if (result != OHOS::FileAccessFwk::ERR_OK) {
HILOG_ERROR("ListFile failed. ret : %{public}d", result); HILOG_ERROR("ListFile failed. ret : %{public}d", result);
return false; return false;
@ -446,4 +449,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::ScanFileFuzzTest(data, size); OHOS::ScanFileFuzzTest(data, size);
OHOS::GetFileInfoFromUriFuzzTest(data, size); OHOS::GetFileInfoFromUriFuzzTest(data, size);
return 0; return 0;
} }

View File

@ -288,11 +288,13 @@ HWTEST_F(AbnormalFileExtensionHelperTest, abnormal_external_file_access_ListFile
try { try {
FileInfo fileInfo; FileInfo fileInfo;
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 0;
FileFilter filter; FileFilter filter;
vector<FileInfo> fileInfoVec; SharedMemoryInfo memInfo;
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, E_PERMISSION_SYS); EXPECT_EQ(result, E_PERMISSION_SYS);
SharedMemoryOperation::DestroySharedMemory(memInfo);
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "abnormal_external_file_access_ListFile_0000 occurs an exception."; GTEST_LOG_(ERROR) << "abnormal_external_file_access_ListFile_0000 occurs an exception.";
} }
@ -469,4 +471,4 @@ HWTEST_F(AbnormalFileExtensionHelperTest, abnormal_external_file_access_GetFileI
GTEST_LOG_(INFO) << "AbnormalFileExtensionHelperTest-end" GTEST_LOG_(INFO) << "AbnormalFileExtensionHelperTest-end"
"abnormal_external_file_access_GetFileInfoFromRelativePath_0000"; "abnormal_external_file_access_GetFileInfoFromRelativePath_0000";
} }
} // namespace } // namespace

View File

@ -23,6 +23,7 @@
#include "accesstoken_kit.h" #include "accesstoken_kit.h"
#include "context_impl.h" #include "context_impl.h"
#include "file_access_framework_errno.h" #include "file_access_framework_errno.h"
#include "file_info_shared_memory.h"
#include "iservice_registry.h" #include "iservice_registry.h"
#include "nativetoken_kit.h" #include "nativetoken_kit.h"
#include "token_setproc.h" #include "token_setproc.h"
@ -3046,14 +3047,16 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0000, testing::e
FileInfo fileInfo; FileInfo fileInfo;
fileInfo.uri = newDirUriTest.ToString(); fileInfo.uri = newDirUriTest.ToString();
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
std::vector<FileInfo> fileInfoVec;
FileFilter filter; 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_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); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} }
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0000 occurs an exception."; 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 fileInfo;
fileInfo.uri = sourceFileUri.ToString(); fileInfo.uri = sourceFileUri.ToString();
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
std::vector<FileInfo> fileInfoVec;
FileFilter filter; 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_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 (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0001 occurs an exception."; 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(); fileInfo.uri = sourceFileUri.ToString();
Uri sourceFile(fileInfo.uri); Uri sourceFile(fileInfo.uri);
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
std::vector<FileInfo> fileInfoVec;
FileFilter filter; 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_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); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} }
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0002 occurs an exception."; 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(); fileInfo.uri = sourceFileUri.ToString();
Uri sourceFile(fileInfo.uri); Uri sourceFile(fileInfo.uri);
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
std::vector<FileInfo> fileInfoVec;
FileFilter filter; 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_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 (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0003 occurs an exception."; GTEST_LOG_(ERROR) << "external_file_access_ListFile_0003 occurs an exception.";
} }
GTEST_LOG_(INFO) << "FileExtensionHelperTest-end external_file_access_ListFile_0003"; GTEST_LOG_(INFO) << "FileExtensionHelperTest-end external_file_access_ListFile_0003";
} }
static void ListFileTdd(FileInfo fileInfo, int offset, int maxCount, FileFilter filter, static void ListFileTdd(FileInfo fileInfo, int offset, FileFilter filter,
std::vector<FileInfo> fileInfoVec) SharedMemoryInfo &memInfo)
{ {
GTEST_LOG_(INFO) << "FileExtensionHelperTest-begin external_file_access_ListFileTdd"; 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) { if (ret != OHOS::FileAccessFwk::ERR_OK) {
GTEST_LOG_(ERROR) << "ListFile get result error, code:" << ret; GTEST_LOG_(ERROR) << "ListFile get result error, code:" << ret;
return; return;
@ -3205,17 +3214,19 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0004, testing::e
FileInfo fileInfo; FileInfo fileInfo;
fileInfo.uri = newDirUriTest.ToString(); fileInfo.uri = newDirUriTest.ToString();
int offset = 0; int offset = 0;
int maxCount = 1000;
std::vector<FileInfo> fileInfoVec;
FileFilter filter; FileFilter filter;
g_num = 0; g_num = 0;
SharedMemoryInfo memInfo;
result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
memInfo);
for (int j = 0; j < INIT_THREADS_NUMBER; j++) { 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(); execthread.join();
} }
EXPECT_EQ(g_num, INIT_THREADS_NUMBER); EXPECT_EQ(g_num, INIT_THREADS_NUMBER);
result = g_fah->Delete(newDirUriTest); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} }
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0004 occurs an exception."; 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 fileInfo;
fileInfo.uri = str; fileInfo.uri = str;
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
std::vector<FileInfo> fileInfoVec;
FileFilter filter; 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); EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
result = g_fah->Delete(newDirUriTest); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} }
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0005 occurs an exception."; 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 fileInfo;
fileInfo.uri = newDirUriTest.ToString(); fileInfo.uri = newDirUriTest.ToString();
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
std::vector<FileInfo> fileInfoVec;
FileFilter filter; 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_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); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} }
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_ListFile_0006 occurs an exception."; 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"; GTEST_LOG_(INFO) << "FileExtensionHelperTest-end external_file_access_ListFile_0006";
} }
static void WriteData(Uri &uri) static void WriteData(Uri &uri)
{ {
int fd = -1; int fd = -1;
@ -3365,12 +3379,14 @@ static void ListFileFilter7(Uri newDirUriTest)
FileInfo fileInfo; FileInfo fileInfo;
fileInfo.uri = newDirUriTest.ToString(); fileInfo.uri = newDirUriTest.ToString();
int64_t offset = 4; int64_t offset = 4;
int64_t maxCount = 1; SharedMemoryInfo memInfo;
std::vector<FileInfo> fileInfoVec;
FileFilter filter({".txt", ".docx"}, {}, {}, -1, -1, false, true); 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(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; 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; GTEST_LOG_(INFO) << caseNumber << ", uri:" << fileInfo.uri << endl;
} }
} }
@ -3429,13 +3447,15 @@ static void ListFileFilter8(Uri newDirUriTest)
FileInfo fileInfo; FileInfo fileInfo;
fileInfo.uri = newDirUriTest.ToString(); fileInfo.uri = newDirUriTest.ToString();
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000; SharedMemoryInfo memInfo;
std::vector<FileInfo> fileInfoVec;
FileFilter filter({}, {}, {}, -1, 0, false, true); 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(result, OHOS::FileAccessFwk::ERR_OK);
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_6); EXPECT_EQ(memInfo.Size(), FILE_COUNT_6);
ShowInfo(fileInfoVec, "external_file_access_ListFile_0008"); ShowInfo(memInfo, "external_file_access_ListFile_0008");
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} }
/** /**
@ -3475,12 +3495,14 @@ static void ListFileFilter9(Uri newDirUriTest)
FileInfo fileInfo; FileInfo fileInfo;
fileInfo.uri = newDirUriTest.ToString(); fileInfo.uri = newDirUriTest.ToString();
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000; SharedMemoryInfo memInfo;
std::vector<FileInfo> fileInfoVec;
FileFilter filter; 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(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 fileInfo;
fileInfo.uri = newDirUriTest.ToString(); fileInfo.uri = newDirUriTest.ToString();
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000; SharedMemoryInfo memInfo;
std::vector<FileInfo> fileInfoVec;
FileFilter filter({".txt", ".docx"}, {}, {}, -1, -1, false, true); 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(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); 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(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); 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(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); 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(result, OHOS::FileAccessFwk::ERR_OK);
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_2); EXPECT_EQ(memInfo.Size(), FILE_COUNT_2);
double nowTime = GetTime(); double nowTime = GetTime();
FileFilter filter4({".txt", ".docx"}, {"0010.txt", "0010.docx"}, {}, -1, nowTime, false, true); 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(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 fileInfo;
fileInfo.uri = newDirUriTest.ToString(); fileInfo.uri = newDirUriTest.ToString();
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000; SharedMemoryInfo memInfo;
std::vector<FileInfo> fileInfoVec; int result = FileAccessFwk::SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB,
memInfo);
FileFilter filter({".txt", ".docx"}, {}, {}, -1, -1, false, true); 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(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); 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(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); 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(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); 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(result, OHOS::FileAccessFwk::ERR_OK);
EXPECT_EQ(fileInfoVec.size(), FILE_COUNT_2); EXPECT_EQ(memInfo.Size(), FILE_COUNT_2);
double nowTime = GetTime(); double nowTime = GetTime();
FileFilter filter4({".txt", ".docx"}, {"测试.txt", "测试.docx"}, {}, -1, nowTime, false, true); 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(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; vector<RootInfo> info;
int result = g_fah->GetRoots(info); int result = g_fah->GetRoots(info);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); 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++) { for (size_t i = 0; i < info.size(); i++) {
Uri parentUri(info[i].uri); Uri parentUri(info[i].uri);
FileInfo fileinfo; FileInfo fileinfo;
@ -4147,13 +4176,12 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0000,
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
FileFilter filter; FileFilter filter;
std::vector<FileInfo> fileInfoVecTemp; result = g_fah->ListFile(fileinfo, offset, filter, memInfo);
result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); 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 (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0000 occurs an exception."; 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; vector<RootInfo> info;
int result = g_fah->GetRoots(info); int result = g_fah->GetRoots(info);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); 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++) { for (size_t i = 0; i < info.size(); i++) {
Uri parentUri(info[i].uri); Uri parentUri(info[i].uri);
Uri newDirUriTest(""); Uri newDirUriTest("");
@ -4188,16 +4219,15 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0001,
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
FileFilter filter; FileFilter filter;
std::vector<FileInfo> fileInfoVec; result = g_fah->ListFile(dirInfo, offset, filter, memInfo);
result = g_fah->ListFile(dirInfo, offset, maxCount, filter, fileInfoVec);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); 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); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
} }
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0001 occurs an exception."; 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; vector<RootInfo> info;
int result = g_fah->GetRoots(info); int result = g_fah->GetRoots(info);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); 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++) { for (size_t i = 0; i < info.size(); i++) {
Uri parentUri(info[i].uri); Uri parentUri(info[i].uri);
Uri newDirUriTest(""); Uri newDirUriTest("");
@ -4235,16 +4268,15 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0002,
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
FileFilter filter; FileFilter filter;
std::vector<FileInfo> fileInfoVecTemp; result = g_fah->ListFile(fileinfo, offset, filter, memInfo);
result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp);
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); 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); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
} }
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0002 occurs an exception."; 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; vector<RootInfo> info;
int result = g_fah->GetRoots(info); int result = g_fah->GetRoots(info);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); 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++) { for (size_t i = 0; i < info.size(); i++) {
Uri parentUri(info[i].uri); Uri parentUri(info[i].uri);
Uri newDirUriTest(""); Uri newDirUriTest("");
@ -4375,16 +4410,15 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0006,
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
FileFilter filter; FileFilter filter;
std::vector<FileInfo> fileInfoVec; result = g_fah->ListFile(dirInfo, offset, filter, memInfo);
result = g_fah->ListFile(dirInfo, offset, maxCount, filter, fileInfoVec);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); 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); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
} }
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0006 occurs an exception."; 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; vector<RootInfo> info;
int result = g_fah->GetRoots(info); int result = g_fah->GetRoots(info);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); 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++) { for (size_t i = 0; i < info.size(); i++) {
Uri parentUri(info[i].uri); Uri parentUri(info[i].uri);
Uri newDirUriTest(""); Uri newDirUriTest("");
@ -4424,16 +4461,16 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0007,
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
int64_t offset = 0; int64_t offset = 0;
int64_t maxCount = 1000;
FileFilter filter; FileFilter filter;
std::vector<FileInfo> fileInfoVecTemp; 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_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); result = g_fah->Delete(newDirUriTest);
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
} }
FileAccessFwk::SharedMemoryOperation::DestroySharedMemory(memInfo);
} catch (...) { } catch (...) {
GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0007 occurs an exception."; GTEST_LOG_(ERROR) << "external_file_access_GetFileInfoFromUri_0007 occurs an exception.";
} }
@ -6074,4 +6111,4 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Move_file_005, testing::e
} }
GTEST_LOG_(INFO) << "FileExtensionHelperTest-end external_file_access_Move_file_0005"; GTEST_LOG_(INFO) << "FileExtensionHelperTest-end external_file_access_Move_file_0005";
} }
} // namespace } // namespace