diff --git a/frameworks/js/napi/file_access_module/BUILD.gn b/frameworks/js/napi/file_access_module/BUILD.gn index b521481fab9373392e02be0bdc5609df342bfac9..58dc8288abbb94b5f56b91c4b08b571b4046ae4c 100644 --- a/frameworks/js/napi/file_access_module/BUILD.gn +++ b/frameworks/js/napi/file_access_module/BUILD.gn @@ -41,7 +41,10 @@ ohos_shared_library("fileaccess") { "root_info/napi_root_iterator_exporter.cpp", ] - deps = [ "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit" ] + deps = [ + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", + "//third_party/jsoncpp:jsoncpp", + ] external_deps = [ "ability_base:want", diff --git a/frameworks/js/napi/file_access_module/file_info/file_info_entity.h b/frameworks/js/napi/file_access_module/file_info/file_info_entity.h index 3450af5b38a9c545f52486ffeba6d19552c5df4d..ee1687e4c60eebaeb9db99f0d8e6c0a6496aaaa6 100644 --- a/frameworks/js/napi/file_access_module/file_info/file_info_entity.h +++ b/frameworks/js/napi/file_access_module/file_info/file_info_entity.h @@ -27,7 +27,7 @@ using namespace DistributedFS; struct FileInfoEntity { FileAccessHelper *fileAccessHelper { nullptr }; FileInfo fileInfo; - FileFilter filter { {}, {}, {}, 0, 0, false, false }; + std::string filter; }; } // namespace FileAccessFwk } // namespace OHOS diff --git a/frameworks/js/napi/file_access_module/file_info/file_iterator_entity.h b/frameworks/js/napi/file_access_module/file_info/file_iterator_entity.h index b945eb29832109c03affd0c6c7e6c2e973233ccb..44580a205fb4b9abc31035418b2c9ce9606790cb 100644 --- a/frameworks/js/napi/file_access_module/file_info/file_iterator_entity.h +++ b/frameworks/js/napi/file_access_module/file_info/file_iterator_entity.h @@ -36,7 +36,7 @@ struct FileIteratorEntity { std::vector fileInfoVec; int64_t offset { 0 }; uint64_t pos { 0 }; - FileFilter filter { {}, {}, {}, 0, 0, false, false }; + std::string filter; int flag { 0 }; }; } // namespace FileAccessFwk diff --git a/frameworks/js/napi/file_access_module/file_info/napi_file_info_exporter.cpp b/frameworks/js/napi/file_access_module/file_info/napi_file_info_exporter.cpp index 676fd18ed77b06dd32213cf39ce4ee7b7e04555e..137e5b20e54504cad93741902950eeb1f801894d 100644 --- a/frameworks/js/napi/file_access_module/file_info/napi_file_info_exporter.cpp +++ b/frameworks/js/napi/file_access_module/file_info/napi_file_info_exporter.cpp @@ -87,13 +87,12 @@ napi_value NapiFileInfoExporter::ListFile(napi_env env, napi_callback_info info) return nullptr; } - FileFilter filter({}, {}, {}, 0, 0, false, false); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - auto ret = GetFileFilterParam(NVal(env, funcArg.GetArg(NARG_POS::FIRST)), filter); - if (ret != ERR_OK) { - NError(ret).ThrowErr(env); - return nullptr; - } + bool succ = false; + std::unique_ptr filter; + std::tie(succ, filter, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); + if (!succ) { + NError(EINVAL).ThrowErr(env); + return nullptr; } auto fileInfoEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); @@ -131,7 +130,7 @@ napi_value NapiFileInfoExporter::ListFile(napi_env env, napi_callback_info info) fileIteratorEntity->fileInfoVec.clear(); fileIteratorEntity->offset = 0; fileIteratorEntity->pos = 0; - fileIteratorEntity->filter = std::move(filter); + fileIteratorEntity->filter = filter.get(); fileIteratorEntity->flag = 0; auto ret = fileInfoEntity->fileAccessHelper->ListFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset, MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec); @@ -152,13 +151,12 @@ napi_value NapiFileInfoExporter::ScanFile(napi_env env, napi_callback_info info) return nullptr; } - FileFilter filter({}, {}, {}, 0, 0, false, false); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - auto ret = GetFileFilterParam(NVal(env, funcArg.GetArg(NARG_POS::FIRST)), filter); - if (ret != ERR_OK) { - NError(ret).ThrowErr(env); - return nullptr; - } + bool succ = false; + std::unique_ptr filter; + std::tie(succ, filter, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); + if (!succ) { + NError(EINVAL).ThrowErr(env); + return nullptr; } auto fileInfoEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); @@ -196,7 +194,7 @@ napi_value NapiFileInfoExporter::ScanFile(napi_env env, napi_callback_info info) fileIteratorEntity->fileInfoVec.clear(); fileIteratorEntity->offset = 0; fileIteratorEntity->pos = 0; - fileIteratorEntity->filter = std::move(filter); + fileIteratorEntity->filter = filter.get(); fileIteratorEntity->flag = 1; auto ret = fileInfoEntity->fileAccessHelper->ScanFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset, MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec); diff --git a/frameworks/js/napi/file_access_module/root_info/napi_root_info_exporter.cpp b/frameworks/js/napi/file_access_module/root_info/napi_root_info_exporter.cpp index f8ee7085ccd37fd310f9a8726d71a9cae02df98e..67a555e2438290fc3a279030e09dce2966996136 100644 --- a/frameworks/js/napi/file_access_module/root_info/napi_root_info_exporter.cpp +++ b/frameworks/js/napi/file_access_module/root_info/napi_root_info_exporter.cpp @@ -89,15 +89,14 @@ napi_value NapiRootInfoExporter::ListFile(napi_env env, napi_callback_info info) return nullptr; } - FileFilter filter({}, {}, {}, 0, 0, false, false); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - auto ret = GetFileFilterParam(NVal(env, funcArg.GetArg(NARG_POS::FIRST)), filter); - if (ret != ERR_OK) { - NError(ret).ThrowErr(env); - return nullptr; - } + bool succ = false; + std::unique_ptr filter; + std::tie(succ, filter, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); + if (!succ) { + NError(EINVAL).ThrowErr(env); + return nullptr; } - + auto rootEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); if (rootEntity == nullptr) { NError(E_GETRESULT).ThrowErr(env); @@ -131,10 +130,10 @@ napi_value NapiRootInfoExporter::ListFile(napi_env env, napi_callback_info info) fileIteratorEntity->fileInfoVec.clear(); fileIteratorEntity->offset = 0; fileIteratorEntity->pos = 0; - fileIteratorEntity->filter = std::move(filter); + fileIteratorEntity->filter = filter.get(); fileIteratorEntity->flag = 0; auto ret = rootEntity->fileAccessHelper->ListFile(fileInfo, fileIteratorEntity->offset, - MAX_COUNT, filter, fileIteratorEntity->fileInfoVec); + MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec); if (ret != ERR_OK) { NError(ret).ThrowErr(env); return nullptr; @@ -152,13 +151,12 @@ napi_value NapiRootInfoExporter::ScanFile(napi_env env, napi_callback_info info) return nullptr; } - FileFilter filter({}, {}, {}, 0, 0, false, false); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - auto ret = GetFileFilterParam(NVal(env, funcArg.GetArg(NARG_POS::FIRST)), filter); - if (ret != ERR_OK) { - NError(ret).ThrowErr(env); - return nullptr; - } + bool succ = false; + std::unique_ptr filter; + std::tie(succ, filter, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); + if (!succ) { + NError(EINVAL).ThrowErr(env); + return nullptr; } auto rootEntity = NClass::GetEntityOf(env, funcArg.GetThisVar()); @@ -194,10 +192,10 @@ napi_value NapiRootInfoExporter::ScanFile(napi_env env, napi_callback_info info) fileIteratorEntity->fileInfoVec.clear(); fileIteratorEntity->offset = 0; fileIteratorEntity->pos = 0; - fileIteratorEntity->filter = std::move(filter); + fileIteratorEntity->filter = filter.get(); fileIteratorEntity->flag = 1; auto ret = rootEntity->fileAccessHelper->ScanFile(fileInfo, fileIteratorEntity->offset, - MAX_COUNT, filter, fileIteratorEntity->fileInfoVec); + MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec); if (ret != ERR_OK) { NError(ret).ThrowErr(env); return nullptr; diff --git a/interfaces/inner_api/file_access/include/file_access_ext_ability.h b/interfaces/inner_api/file_access/include/file_access_ext_ability.h index 6fa8093fb099388bc8b728e1714c2d1bbf953084..42787d0860fd97810d1f5879b7ed07ff73bb8856 100644 --- a/interfaces/inner_api/file_access/include/file_access_ext_ability.h +++ b/interfaces/inner_api/file_access/include/file_access_ext_ability.h @@ -52,9 +52,9 @@ public: virtual int Copy(const Uri &sourceUri, const Uri &destUri, std::vector ©Result, bool force = false); virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile); virtual int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec); + const std::string &filter, std::vector &fileInfoVec); virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec); + const std::string &filter, std::vector &fileInfoVec); virtual int GetThumbnail(const Uri &uri, const Size &size, std::unique_ptr &pixelMap); virtual int Query(const Uri &uri, std::vector &columns, std::vector &results); virtual int GetFileInfoFromUri(const Uri &selectFile, FileInfo &fileInfo); diff --git a/interfaces/inner_api/file_access/include/file_access_ext_proxy.h b/interfaces/inner_api/file_access/include/file_access_ext_proxy.h index 1944b0b42e156f9ae0a4aaca97b08bc411a005d2..7b226e55bd0cfc0d6844528f8bde8aa1966729cc 100644 --- a/interfaces/inner_api/file_access/include/file_access_ext_proxy.h +++ b/interfaces/inner_api/file_access/include/file_access_ext_proxy.h @@ -47,9 +47,9 @@ public: 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 &fileInfoVec) override; + const std::string &filter, std::vector &fileInfoVec) override; virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) override; + const std::string &filter, std::vector &fileInfoVec) override; virtual int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize, std::shared_ptr &pixelMap) override; virtual int Query(const Uri &uri, std::vector &columns, std::vector &results) override; virtual int GetFileInfoFromUri(const Uri &selectFile, FileInfo &fileInfo) override; diff --git a/interfaces/inner_api/file_access/include/file_access_ext_stub_impl.h b/interfaces/inner_api/file_access/include/file_access_ext_stub_impl.h index aa8af22fe49bb3c72004be25ee38d9691f886485..2726b91b41e915f0b52ae083b3726ed35825abda 100644 --- a/interfaces/inner_api/file_access/include/file_access_ext_stub_impl.h +++ b/interfaces/inner_api/file_access/include/file_access_ext_stub_impl.h @@ -45,9 +45,9 @@ public: 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 &fileInfoVec) override; + const std::string &filter, std::vector &fileInfoVec) override; int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) override; + const std::string &filter, std::vector &fileInfoVec) override; int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize, std::shared_ptr &pixelMap) override; int Query(const Uri &uri, std::vector &columns, std::vector &results) override; int GetFileInfoFromUri(const Uri &selectFile, FileInfo &fileInfo) override; diff --git a/interfaces/inner_api/file_access/include/file_access_helper.h b/interfaces/inner_api/file_access/include/file_access_helper.h index fc1838242108aa53c62c0bcc15b4aceea083d99d..670508bd1fd53d3078706005bbdee89ecdea2ac5 100644 --- a/interfaces/inner_api/file_access/include/file_access_helper.h +++ b/interfaces/inner_api/file_access/include/file_access_helper.h @@ -77,9 +77,9 @@ public: int Move(Uri &sourceFile, Uri &targetParent, Uri &newFile); int Copy(Uri &sourceUri, Uri &destUri, std::vector ©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, + int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const std::string &filter, std::vector &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 std::string &filter, std::vector &fileInfoVec); int GetThumbnail(Uri &uri, ThumbnailSize &thumbnailSize, std::shared_ptr &pixelMap); int Query(Uri &uri, std::string &metaJson); diff --git a/interfaces/inner_api/file_access/include/ifile_access_ext_base.h b/interfaces/inner_api/file_access/include/ifile_access_ext_base.h index 70b459f622bc8871ac21ee0dea79c55cf48573c8..28373335841200ea6b4c349006d503a4ba5c790e 100644 --- a/interfaces/inner_api/file_access/include/ifile_access_ext_base.h +++ b/interfaces/inner_api/file_access/include/ifile_access_ext_base.h @@ -66,9 +66,9 @@ public: 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 &fileInfoVec) = 0; + const std::string &filter, std::vector &fileInfoVec) = 0; virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) = 0; + const std::string &filter, std::vector &fileInfoVec) = 0; virtual int GetThumbnail(const Uri &uri, const ThumbnailSize &thumbnailSize, std::shared_ptr &pixelMap) = 0; virtual int Query(const Uri &uri, std::vector &columns, std::vector &results) = 0; virtual int GetFileInfoFromUri(const Uri &selectFile, FileInfo &fileInfo) = 0; diff --git a/interfaces/inner_api/file_access/include/js_file_access_ext_ability.h b/interfaces/inner_api/file_access/include/js_file_access_ext_ability.h index ac4b0bd29d7fa48a02365380b026c5d6410d7342..3ded9850c617835777ecab346a858b517b23fec9 100644 --- a/interfaces/inner_api/file_access/include/js_file_access_ext_ability.h +++ b/interfaces/inner_api/file_access/include/js_file_access_ext_ability.h @@ -66,7 +66,7 @@ public: int Delete(const Uri &sourceFile) override; int Move(const Uri &sourceFile, const Uri &targetParent, 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, const FileFilter &filter, + int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, const std::string &filter, std::vector &fileInfoVec) override; int GetFileInfoFromUri(const Uri &selectFile, FileInfo &fileInfo) override; int GetRoots(std::vector &rootInfoVec) override; diff --git a/interfaces/inner_api/file_access/src/file_access_ext_ability.cpp b/interfaces/inner_api/file_access/src/file_access_ext_ability.cpp index 418f6ebb2158acb00a6bce105f8e48d6d3adbb86..0482060c6ed9ed37ce1086c82e0e2ddb2b5eb539 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_ability.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_ability.cpp @@ -104,14 +104,14 @@ int FileAccessExtAbility::Rename(const Uri &sourceFile, const std::string &displ } int FileAccessExtAbility::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { HILOG_ERROR("FileAccessExtAbility::ListFile Undefined operation"); return EPERM; } int FileAccessExtAbility::ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { HILOG_ERROR("FileAccessExtAbility::ScanFile Undefined operation"); return EPERM; diff --git a/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp b/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp index 192c090a40d2b9e236776ec886c64128484b8db4..1143a4f606534662aa1cad09e4ca9eb8096e2cbe 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp @@ -489,7 +489,7 @@ static int GetListFileResult(MessageParcel &reply, std::vector &fileIn } int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "ListFile"); MessageParcel data; @@ -517,8 +517,8 @@ int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, return E_IPCS; } - if (!data.WriteParcelable(&filter)) { - HILOG_ERROR("fail to WriteParcelable filter"); + if (!data.WriteString(filter)) { + HILOG_ERROR("fail to WriteString filter"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return E_IPCS; } @@ -544,7 +544,7 @@ int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset, } int FileAccessExtProxy::ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "ScanFile"); MessageParcel data; @@ -572,8 +572,8 @@ int FileAccessExtProxy::ScanFile(const FileInfo &fileInfo, const int64_t offset, return E_IPCS; } - if (!data.WriteParcelable(&filter)) { - HILOG_ERROR("fail to WriteParcelable filter"); + if (!data.WriteString(filter)) { + HILOG_ERROR("fail to WriteString filter"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return E_IPCS; } diff --git a/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp b/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp index 2f14b23a71594b35e79067595b4106e0fc301b12..f7db7e90dd845ae2eb14485ab9aea86a73f943ae 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_stub.cpp @@ -430,15 +430,15 @@ ErrCode FileAccessExtStub::CmdListFile(MessageParcel &data, MessageParcel &reply return E_IPCS; } - std::shared_ptr filter(data.ReadParcelable()); - if (filter == nullptr) { - HILOG_ERROR("parameter ListFile FileFilter is invalid"); + std::string filter; + if (!data.ReadString(filter)) { + HILOG_ERROR("parameter ListFile filter is invalid"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return E_IPCS; } std::vector fileInfoVec; - int ret = ListFile(*fileInfo, offset, maxCount, *filter, fileInfoVec); + int ret = ListFile(*fileInfo, offset, maxCount, filter, fileInfoVec); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter ListFile fail to WriteInt32 ret"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); @@ -488,15 +488,15 @@ ErrCode FileAccessExtStub::CmdScanFile(MessageParcel &data, MessageParcel &reply return E_IPCS; } - std::shared_ptr filter(data.ReadParcelable()); - if (filter == nullptr) { - HILOG_ERROR("parameter ScanFile FileFilter is invalid"); + std::string filter; + if (!data.ReadString(filter)) { + HILOG_ERROR("parameter ScanFile fileFilter is invalid"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return E_IPCS; } std::vector fileInfoVec; - int ret = ScanFile(*fileInfo, offset, maxCount, *filter, fileInfoVec); + int ret = ScanFile(*fileInfo, offset, maxCount, filter, fileInfoVec); if (!reply.WriteInt32(ret)) { HILOG_ERROR("Parameter ScanFile fail to WriteInt32 ret"); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); diff --git a/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp b/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp index fdf6cf3ab37556e350425774587388c539829435..7127b9e64620b4c213898538fb9f40e7f822f94f 100644 --- a/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp +++ b/interfaces/inner_api/file_access/src/file_access_ext_stub_impl.cpp @@ -127,7 +127,7 @@ int FileAccessExtStubImpl::Rename(const Uri &sourceFile, const std::string &disp } int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "ListFile"); if (extension_ == nullptr) { @@ -142,7 +142,7 @@ int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offs } int FileAccessExtStubImpl::ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "ScanFile"); if (extension_ == nullptr) { diff --git a/interfaces/inner_api/file_access/src/file_access_helper.cpp b/interfaces/inner_api/file_access/src/file_access_helper.cpp index 047d16e189a11b238991523856812f2195140cd5..4d0ab8642c19e820fadb52197f8ad2586e2f9289 100644 --- a/interfaces/inner_api/file_access/src/file_access_helper.cpp +++ b/interfaces/inner_api/file_access/src/file_access_helper.cpp @@ -779,7 +779,7 @@ int FileAccessHelper::Rename(Uri &sourceFile, const std::string &displayName, Ur } int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "ListFile"); if (!IsSystemApp()) { @@ -814,7 +814,7 @@ int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, c } int FileAccessHelper::ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "ScanFile"); if (!IsSystemApp()) { diff --git a/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp b/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp index 1d0f27590a70d19eb81855d7b21113887b806a2b..650134a6500f923dbc28fc8f0e8bee0340f20647 100644 --- a/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp +++ b/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp @@ -24,6 +24,7 @@ #include "hilog_wrapper.h" #include "hitrace_meter.h" #include "ipc_skeleton.h" +#include "json/json.h" #include "js_runtime.h" #include "js_runtime_utils.h" #include "napi/native_api.h" @@ -771,68 +772,92 @@ static int MakeStringNativeArray(NativeEngine &engine, std::vector return ERR_OK; } -static int MakeJsNativeFileFilter(NativeEngine &engine, const FileFilter &filter, NativeValue *nativeFilter) +static std::vector ParseJsonArray(const Json::Value &value, const std::string &key) { - nativeFilter = engine.CreateObject(); - if (nativeFilter == nullptr) { - HILOG_ERROR("Create js NativeValue fail."); - return E_GETRESULT; - } - - NativeValue *suffixArray = engine.CreateArray(filter.GetSuffix().size()); - if (suffixArray == nullptr) { - HILOG_ERROR("Create Suffix native array value fail."); - return E_GETRESULT; + std::vector valueArray; + for (uint32_t i = 0; i < value[key].size(); i++) { + string valueStr = value[key][i].asString(); + valueArray.push_back(valueStr); } + return valueArray; +} - std::vector suffixVec = filter.GetSuffix(); - int errorCode = MakeStringNativeArray(engine, suffixVec, suffixArray); +static int GetNativeArray(NativeEngine &engine, const Json::Value &value, const std::string &key, + NativeValue *nativeValue) +{ + std::vector arrayVec = ParseJsonArray(value, key); + int errorCode = MakeStringNativeArray(engine, arrayVec, nativeValue); if (errorCode != ERR_OK) { HILOG_ERROR("Create Suffix native array value fail, code:%{public}d.", errorCode); return errorCode; } + return ERR_OK; +} - NativeValue *displayNameArray = engine.CreateArray(filter.GetDisplayName().size()); - if (displayNameArray == nullptr) { - HILOG_ERROR("Create DisplayName native array value fail."); - return E_GETRESULT; - } +static int ParseFilter(NativeEngine &engine, const std::string &filter, NativeObject *objFilter) +{ + Json::Reader reader; + Json::Value value; + if (reader.parse(filter, value)) { + NativeValue *suffixArray = nullptr; + int errorCode = GetNativeArray(engine, value, "suffix", suffixArray); + if (errorCode != ERR_OK) { + return errorCode; + } - std::vector displayNameVec = filter.GetDisplayName(); - errorCode = MakeStringNativeArray(engine, displayNameVec, displayNameArray); - if (errorCode != ERR_OK) { - HILOG_ERROR("Create DisplayName native array value fail, code:%{public}d.", errorCode); - return errorCode; - } + NativeValue *displayNameArray = nullptr; + errorCode = GetNativeArray(engine, value, "displayName", displayNameArray); + if (errorCode != ERR_OK) { + return errorCode; + } - NativeValue *mimeTypeArray = engine.CreateArray(filter.GetMimeType().size()); - if (mimeTypeArray == nullptr) { - HILOG_ERROR("Create MimeType native array value fail."); - return E_GETRESULT; - } + NativeValue *mimeTypeArray = nullptr; + errorCode = GetNativeArray(engine, value, "mimeType", mimeTypeArray); + if (errorCode != ERR_OK) { + return errorCode; + } - std::vector mimeTypeVec = filter.GetMimeType(); - errorCode = MakeStringNativeArray(engine, mimeTypeVec, mimeTypeArray); - if (errorCode != ERR_OK) { - HILOG_ERROR("Create MimeType native array value fail, code:%{public}d.", errorCode); - return errorCode; - } + int64_t fileSizeOver = value["fileSizeOver"].asInt64(); + NativeValue *nativeFileSizeOver = engine.CreateNumber(fileSizeOver); + if (nativeFileSizeOver == nullptr) { + HILOG_ERROR("Create NativeFileSizeOver native js value fail."); + return E_GETRESULT; + } - NativeValue *nativeFileSizeOver = engine.CreateNumber(filter.GetFileSizeOver()); - if (nativeFileSizeOver == nullptr) { - HILOG_ERROR("Create NativeFileSizeOver native js value fail."); - return E_GETRESULT; - } + double lastModifiedAfter = value["lastModifiedAfter"].asDouble(); + NativeValue *nativeLastModifiedAfter = engine.CreateNumber(lastModifiedAfter); + if (nativeLastModifiedAfter == nullptr) { + HILOG_ERROR("Create NativeLastModifiedAfter native js value fail."); + return E_GETRESULT; + } - NativeValue *nativeLastModifiedAfter = engine.CreateNumber(filter.GetLastModifiedAfter()); - if (nativeLastModifiedAfter == nullptr) { - HILOG_ERROR("Create NativeLastModifiedAfter native js value fail."); - return E_GETRESULT; + bool excludeMedia = value["excludeMedia"].asBool(); + NativeValue *nativeExcludeMedia = engine.CreateBoolean(excludeMedia); + if (nativeExcludeMedia == nullptr) { + HILOG_ERROR("Create NativeExcludeMedia native js value fail."); + return E_GETRESULT; + } + + bool ret = objFilter->SetProperty("suffix", suffixArray); + ret = ret && objFilter->SetProperty("displayName", displayNameArray); + ret = ret && objFilter->SetProperty("mimeType", mimeTypeArray); + ret = ret && objFilter->SetProperty("fileSizeOver", nativeFileSizeOver); + ret = ret && objFilter->SetProperty("lastModifiedAfter", nativeLastModifiedAfter); + ret = ret && objFilter->SetProperty("excludeMedia", nativeExcludeMedia); + if (!ret) { + HILOG_ERROR("Set property to Filter NativeValue fail."); + return EINVAL; + } } + return ERR_OK; +} - NativeValue *nativeExcludeMedia = engine.CreateBoolean(filter.GetExcludeMedia()); - if (nativeExcludeMedia == nullptr) { - HILOG_ERROR("Create NativeExcludeMedia native js value fail."); +static int MakeJsNativeFileFilter(NativeEngine &engine, const std::string &filter, NativeValue *nativeFilter) +{ + int errorCode = -1; + nativeFilter = engine.CreateObject(); + if (nativeFilter == nullptr) { + HILOG_ERROR("Create js NativeValue fail."); return E_GETRESULT; } @@ -842,22 +867,16 @@ static int MakeJsNativeFileFilter(NativeEngine &engine, const FileFilter &filter return E_GETRESULT; } - bool ret = objFilter->SetProperty("suffix", suffixArray); - ret = ret && objFilter->SetProperty("displayName", displayNameArray); - ret = ret && objFilter->SetProperty("mimeType", mimeTypeArray); - ret = ret && objFilter->SetProperty("fileSizeOver", nativeFileSizeOver); - ret = ret && objFilter->SetProperty("lastModifiedAfter", nativeLastModifiedAfter); - ret = ret && objFilter->SetProperty("excludeMedia", nativeExcludeMedia); - if (!ret) { - HILOG_ERROR("Set property to Filter NativeValue fail."); - return EINVAL; + errorCode = ParseFilter(engine, filter, objFilter); + if (errorCode != ERR_OK) { + return errorCode; } return ERR_OK; } int JsFileAccessExtAbility::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, - const FileFilter &filter, std::vector &fileInfoVec) + const std::string &filter, std::vector &fileInfoVec) { StartTrace(HITRACE_TAG_FILEMANAGEMENT, "ListFile"); auto value = std::make_shared>>(); @@ -888,7 +907,7 @@ int JsFileAccessExtAbility::ListFile(const FileInfo &fileInfo, const int64_t off } NativeValue* nativeFilter = nullptr; - if (filter.GetHasFilter()) { + if (!filter.empty()) { int ret = MakeJsNativeFileFilter(engine, filter, nativeFilter); if (ret != ERR_OK) { HILOG_ERROR("Create js NativeValue fail."); diff --git a/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp b/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp index 9abf1833768e5a699034fcf5f3d82ae0fb2f6f80..b6c522fd2511db67796d304a23eaaeda99bd9507 100644 --- a/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp +++ b/test/fuzztest/externalfileaccess_fuzzer/external_file_access_fuzzer.cpp @@ -372,7 +372,7 @@ bool ListFileFuzzTest(const uint8_t* data, size_t size) int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; int result = helper->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); if (result != OHOS::FileAccessFwk::ERR_OK) { HILOG_ERROR("ListFile failed. ret : %{public}d", result); @@ -398,7 +398,7 @@ bool ScanFileFuzzTest(const uint8_t* data, size_t size) int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; int result = helper->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); if (result != OHOS::FileAccessFwk::ERR_OK) { HILOG_ERROR("ScanFile failed. ret : %{public}d", result); diff --git a/test/fuzztest/medialibraryfileaccess_fuzzer/medialibrary_file_access_fuzzer.cpp b/test/fuzztest/medialibraryfileaccess_fuzzer/medialibrary_file_access_fuzzer.cpp index 1a9e07f011cc4eec7f2b68a0dced19163393c83e..d93632f2b57c80ba1ddfea5e3ba6e26cffd8fac5 100644 --- a/test/fuzztest/medialibraryfileaccess_fuzzer/medialibrary_file_access_fuzzer.cpp +++ b/test/fuzztest/medialibraryfileaccess_fuzzer/medialibrary_file_access_fuzzer.cpp @@ -370,7 +370,7 @@ bool ListFileFuzzTest(const uint8_t* data, size_t size) int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; int result = helper->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); if (result != OHOS::FileAccessFwk::ERR_OK) { HILOG_ERROR("ListFile failed. ret : %{public}d", result); @@ -395,7 +395,7 @@ bool ScanFileFuzzTest(const uint8_t* data, size_t size) int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; int result = helper->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); if (result != OHOS::FileAccessFwk::ERR_OK) { HILOG_ERROR("ScanFile failed. ret : %{public}d", result); diff --git a/test/unittest/external_file_access_test.cpp b/test/unittest/external_file_access_test.cpp index 3b2e897f2b5222c008598ec5ac267af5db774ba5..c8ef05ec74f8e9c073b65c56b6ae4f38ad86862a 100644 --- a/test/unittest/external_file_access_test.cpp +++ b/test/unittest/external_file_access_test.cpp @@ -2080,7 +2080,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0000, testing::e int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_GT(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2112,7 +2112,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0001, testing::e int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2153,7 +2153,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0002, testing::e int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2186,7 +2186,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0003, testing::e int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2196,7 +2196,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0003, testing::e 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, int maxCount, std::string filter, std::vector fileInfoVec) { GTEST_LOG_(INFO) << "FileExtensionHelperTest-begin external_file_access_ListFileTdd"; @@ -2239,7 +2239,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0004, testing::e int offset = 0; int maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; g_num = 0; for (int j = 0; j < INIT_THREADS_NUMBER; j++) { std::thread execthread(ListFileTdd, fileInfo, offset, maxCount, filter, fileInfoVec); @@ -2290,7 +2290,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0005, testing::e int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS); result = g_fah->Delete(newDirUriTest); @@ -2441,7 +2441,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0000, int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + std::string filter; std::vector fileInfoVecTemp; result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); @@ -2482,7 +2482,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0001, int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + std::string filter; std::vector fileInfoVec; result = g_fah->ListFile(dirInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); @@ -2529,7 +2529,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_GetFileInfoFromUri_0002, int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + std::string filter; std::vector fileInfoVecTemp; result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); diff --git a/test/unittest/medialibrary_file_access_test.cpp b/test/unittest/medialibrary_file_access_test.cpp index 3d890cb44de128cb62c553cf01179f24654254ad..78fd3864b5e26cc9bf70473dc9f4864ba6572baf 100644 --- a/test/unittest/medialibrary_file_access_test.cpp +++ b/test/unittest/medialibrary_file_access_test.cpp @@ -149,7 +149,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_OpenFile_0000, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_GE(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2054,7 +2054,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0000, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter; + std::string filter; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_GT(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2086,7 +2086,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0001, testing:: int64_t offset = 0; int64_t maxCount = 1000; vector fileInfoVec; - FileFilter filter({}, {}, {}, 0, 0, false, false); + string filter; int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2122,7 +2122,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0002, testing:: int64_t offset = 0; int64_t maxCount = 1000; vector fileInfoVec; - FileFilter filter({}, {}, {}, 0, 0, false, false); + string filter; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2154,7 +2154,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0003, testing:: int64_t offset = 0; int64_t maxCount = 1000; vector fileInfoVec; - FileFilter filter; + string filter; int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK); @@ -2192,7 +2192,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0004, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter({".txt"}, {}, {}, 0, 0, false, true); + string filter = "{\"suffix\":[\".txt\"]}"; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), 1); @@ -2205,7 +2205,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0004, testing:: } static void ListFileTdd(shared_ptr fahs, FileInfo fileInfo, int offset, int maxCount, - FileFilter filter, std::vector fileInfoVec) + string filter, std::vector fileInfoVec) { GTEST_LOG_(INFO) << "FileAccessHelperTest-begin medialibrary_file_access_ListFileTdd"; int ret = fahs->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); @@ -2247,7 +2247,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0005, testing:: int64_t maxCount = 1000; std::vector fileInfoVec; g_num = 0; - FileFilter filter({".txt"}, {}, {}, 0, 0, false, true); + string filter = "{\"suffix\":[\".txt\"]}"; for (int j = 0; j < INIT_THREADS_NUMBER; j++) { std::thread execthread(ListFileTdd, g_fah, fileInfo, offset, maxCount, filter, fileInfoVec); execthread.join(); @@ -2287,7 +2287,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ScanFile_0000, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter({".q1w2e3r4"}, {}, {}, 0, 0, false, true); + string filter = "{\"suffix\":[\".q1w2e3r4\"]}"; result = g_fah->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_GE(fileInfoVec.size(), 1); @@ -2326,7 +2326,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ScanFile_0001, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter({}, {}, {}, 0, 0, false, false); + string filter; result = g_fah->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_GE(fileInfoVec.size(), 2); @@ -2367,11 +2367,11 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ScanFile_0002, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter({".q1w2e3r4"}, {}, {}, 0, 0, false, true); + string filter = "{\"suffix\":[\".q1w2e3r4\"]}"; result = g_fah->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), 1); - FileFilter filter1({".q1w2e3r4", ".txt"}, {}, {}, 0, 0, false, true); + string filter1 = "{\"suffix\":[\".q1w2e3r4\",\".txt\"]}"; result = g_fah->ScanFile(fileInfo, offset, maxCount, filter1, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), 2); @@ -2408,7 +2408,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ScanFile_0003, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter({".q1w2e3r4"}, {}, {}, 0, 0, false, true); + string filter = "{\"suffix\":[\".q1w2e3r4\"]}"; result = g_fah->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); EXPECT_EQ(fileInfoVec.size(), 1); @@ -2421,7 +2421,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ScanFile_0003, testing:: GTEST_LOG_(INFO) << "FileAccessHelperTest-end medialibrary_file_access_ScanFile_0003"; } -static void ScanFileTdd(FileInfo fileInfo, int offset, int maxCount, FileFilter filter, +static void ScanFileTdd(FileInfo fileInfo, int offset, int maxCount, string filter, std::vector fileInfoVec) { GTEST_LOG_(INFO) << "FileAccessHelperTest-begin medialibrary_file_access_ScanFileTdd"; @@ -2462,7 +2462,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ScanFile_0004, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter({".q1w2e3r4"}, {}, {}, 0, 0, false, true); + string filter = "{\"suffix\":[\".q1w2e3r4\"]}"; g_num = 0; for (int j = 0; j < INIT_THREADS_NUMBER; j++) { std::thread execthread(ScanFileTdd, fileInfo, offset, maxCount, filter, fileInfoVec); @@ -2531,7 +2531,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ScanFile_0005, testing:: int64_t offset = 0; int64_t maxCount = 1000; std::vector fileInfoVec; - FileFilter filter({".q1w2e3r4"}, {}, {}, 0, 0, false, true); + string filter = "{\"suffix\":[\".q1w2e3r4\"]}"; result = g_fah->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS); EXPECT_EQ(fileInfoVec.size(), 0); @@ -2604,7 +2604,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_GetFileInfoFromUri_0000, int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + string filter; std::vector fileInfoVecTemp; result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); @@ -2640,7 +2640,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_GetFileInfoFromUri_0001, int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + string filter; std::vector fileInfoVec; result = g_fah->ListFile(dirInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); @@ -2681,7 +2681,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_GetFileInfoFromUri_0002, int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + string filter; std::vector fileInfoVecTemp; result = g_fah->ListFile(fileinfo, offset, maxCount, filter, fileInfoVecTemp); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); @@ -2900,7 +2900,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_GetFileInfoFromRelativeP int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + string filter; std::vector fileInfoVec; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK); @@ -2944,7 +2944,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_GetFileInfoFromRelativeP int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + string filter; std::vector fileInfoVec; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK); @@ -2994,7 +2994,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_GetFileInfoFromRelativeP int64_t offset = 0; int64_t maxCount = 1000; - FileFilter filter; + string filter; std::vector fileInfoVec; result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec); EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);