mirror of
https://gitee.com/openharmony/filemanagement_user_file_service
synced 2024-11-23 07:20:41 +00:00
modify errorcode and napi throw error message
Signed-off-by: onexiaomin <wangminmin4@huawei.com>
This commit is contained in:
parent
69381ebc99
commit
2c5fbbc45f
@ -20,6 +20,7 @@
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include "bundle_mgr_interface.h"
|
||||
#include "context.h"
|
||||
@ -59,10 +60,11 @@ public:
|
||||
// get all ability want info
|
||||
static int GetRegisteredFileAccessExtAbilityInfo(std::vector<AAFwk::Want> &wantVec);
|
||||
// create and connect all ability
|
||||
static std::shared_ptr<FileAccessHelper> Creator(const std::shared_ptr<OHOS::AbilityRuntime::Context> &context);
|
||||
static std::pair<std::shared_ptr<FileAccessHelper>, int>
|
||||
Creator(const std::shared_ptr<OHOS::AbilityRuntime::Context> &context);
|
||||
// create and connect with want, if created, only connect with want
|
||||
static std::shared_ptr<FileAccessHelper> Creator(const std::shared_ptr<OHOS::AbilityRuntime::Context> &context,
|
||||
const std::vector<AAFwk::Want> &wants);
|
||||
static std::pair<std::shared_ptr<FileAccessHelper>, int>
|
||||
Creator(const std::shared_ptr<OHOS::AbilityRuntime::Context> &context, const std::vector<AAFwk::Want> &wants);
|
||||
static std::shared_ptr<FileAccessHelper> Creator(const sptr<IRemoteObject> &token,
|
||||
const std::vector<AAFwk::Want> &wants);
|
||||
|
||||
|
@ -64,69 +64,69 @@ void FileAccessExtAbility::Init(const std::shared_ptr<AbilityLocalRecord> &recor
|
||||
int FileAccessExtAbility::OpenFile(const Uri &uri, const int flags, int &fd)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::OpenFile Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::CreateFile Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::Mkdir Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::Delete(const Uri &sourceFile)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::Delete Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::Move Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::Rename Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::ListFile Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
|
||||
const FileFilter &filter, std::vector<FileInfo> &fileInfoVec)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::ScanFile Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::GetRoots(std::vector<RootInfo> &rootInfoVec)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::GetRoots Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::UriToFileInfo Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
int FileAccessExtAbility::Access(const Uri &uri, bool &isExist)
|
||||
{
|
||||
HILOG_ERROR("FileAccessExtAbility::IsFileExist Undefined operation");
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
bool FileAccessExtAbility::GetNotifyManager()
|
||||
@ -146,7 +146,7 @@ int FileAccessExtAbility::RegisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
if (!GetNotifyManager()) {
|
||||
HILOG_ERROR("GetNotifyManager fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return E_REGISTER;
|
||||
}
|
||||
int ret = notifyManager_->RegisterNotify(notify);
|
||||
if (ret != ERR_OK) {
|
||||
@ -162,7 +162,7 @@ int FileAccessExtAbility::UnregisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
if (!GetNotifyManager()) {
|
||||
HILOG_ERROR("GetNotifyManager fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return E_REMOVE;
|
||||
}
|
||||
int ret = notifyManager_->UnregisterNotify(notify);
|
||||
if (ret != ERR_OK) {
|
||||
@ -178,7 +178,7 @@ int FileAccessExtAbility::Notify(const NotifyMessage& message)
|
||||
if (!GetNotifyManager()) {
|
||||
HILOG_ERROR("GetNotifyManager fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return E_NOTIFY;
|
||||
}
|
||||
int ret = notifyManager_->Notify(message);
|
||||
if (ret != ERR_OK) {
|
||||
|
@ -31,19 +31,19 @@ int FileAccessExtProxy::OpenFile(const Uri &uri, const int flags, int &fd)
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&uri)) {
|
||||
HILOG_ERROR("fail to WriteParcelable uri");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(flags)) {
|
||||
HILOG_ERROR("fail to WriteInt32 flags");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -55,11 +55,11 @@ int FileAccessExtProxy::OpenFile(const Uri &uri, const int flags, int &fd)
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -72,7 +72,7 @@ int FileAccessExtProxy::OpenFile(const Uri &uri, const int flags, int &fd)
|
||||
if (fd < ERR_OK) {
|
||||
HILOG_ERROR("fail to ReadFileDescriptor fd: %{public}d", fd);
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -86,19 +86,19 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&parent)) {
|
||||
HILOG_ERROR("fail to WriteParcelable parent");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteString(displayName)) {
|
||||
HILOG_ERROR("fail to WriteString displayName");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -110,11 +110,11 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -127,14 +127,14 @@ int FileAccessExtProxy::CreateFile(const Uri &parent, const std::string &display
|
||||
if (tempUri == nullptr) {
|
||||
HILOG_ERROR("ReadParcelable value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
newFile = Uri(*tempUri);
|
||||
if (newFile.ToString().empty()) {
|
||||
HILOG_ERROR("get uri is empty.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_RESULT;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -148,19 +148,19 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName,
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&parent)) {
|
||||
HILOG_ERROR("fail to WriteParcelable parent");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteString(displayName)) {
|
||||
HILOG_ERROR("fail to WriteString displayName");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -172,11 +172,11 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName,
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -189,14 +189,14 @@ int FileAccessExtProxy::Mkdir(const Uri &parent, const std::string &displayName,
|
||||
if (tempUri == nullptr) {
|
||||
HILOG_ERROR("ReadParcelable value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
newFile = Uri(*tempUri);
|
||||
if (newFile.ToString().empty()) {
|
||||
HILOG_ERROR("get uri is empty.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_RESULT;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -210,13 +210,13 @@ int FileAccessExtProxy::Delete(const Uri &sourceFile)
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&sourceFile)) {
|
||||
HILOG_ERROR("fail to WriteParcelable sourceFile");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -228,11 +228,11 @@ int FileAccessExtProxy::Delete(const Uri &sourceFile)
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -252,19 +252,19 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&sourceFile)) {
|
||||
HILOG_ERROR("fail to WriteParcelable sourceFile");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&targetParent)) {
|
||||
HILOG_ERROR("fail to WriteParcelable targetParent");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -276,11 +276,11 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -293,14 +293,14 @@ int FileAccessExtProxy::Move(const Uri &sourceFile, const Uri &targetParent, Uri
|
||||
if (tempUri == nullptr) {
|
||||
HILOG_ERROR("ReadParcelable value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
newFile = Uri(*tempUri);
|
||||
if (newFile.ToString().empty()) {
|
||||
HILOG_ERROR("get uri is empty.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_RESULT;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -314,19 +314,19 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&sourceFile)) {
|
||||
HILOG_ERROR("fail to WriteParcelable sourceFile");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteString(displayName)) {
|
||||
HILOG_ERROR("fail to WriteString displayName");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -338,11 +338,11 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -355,14 +355,14 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display
|
||||
if (tempUri == nullptr) {
|
||||
HILOG_ERROR("ReadParcelable value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
newFile = Uri(*tempUri);
|
||||
if (newFile.ToString().empty()) {
|
||||
HILOG_ERROR("get uri is empty.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_RESULT;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -371,10 +371,10 @@ int FileAccessExtProxy::Rename(const Uri &sourceFile, const std::string &display
|
||||
|
||||
static int GetListFileResult(MessageParcel &reply, std::vector<FileInfo> &fileInfoVec)
|
||||
{
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -385,7 +385,7 @@ static int GetListFileResult(MessageParcel &reply, std::vector<FileInfo> &fileIn
|
||||
int64_t count = 0;
|
||||
if (!reply.ReadInt64(count)) {
|
||||
HILOG_ERROR("ListFile operation failed to Read count");
|
||||
return ERR_INVALID_RESULT;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
fileInfoVec.clear();
|
||||
@ -406,31 +406,31 @@ int FileAccessExtProxy::ListFile(const FileInfo &fileInfo, const int64_t offset,
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&fileInfo)) {
|
||||
HILOG_ERROR("fail to WriteParcelable fileInfo");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteInt64(offset)) {
|
||||
HILOG_ERROR("fail to WriteInt64 offset");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteInt64(maxCount)) {
|
||||
HILOG_ERROR("fail to WriteInt64 maxCount");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&filter)) {
|
||||
HILOG_ERROR("fail to WriteParcelable filter");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -461,31 +461,31 @@ int FileAccessExtProxy::ScanFile(const FileInfo &fileInfo, const int64_t offset,
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&fileInfo)) {
|
||||
HILOG_ERROR("fail to WriteParcelable fileInfo");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteInt64(offset)) {
|
||||
HILOG_ERROR("fail to WriteInt64 offset");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteInt64(maxCount)) {
|
||||
HILOG_ERROR("fail to WriteInt64 maxCount");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&filter)) {
|
||||
HILOG_ERROR("fail to WriteParcelable filter");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -515,7 +515,7 @@ int FileAccessExtProxy::GetRoots(std::vector<RootInfo> &rootInfoVec)
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -527,11 +527,11 @@ int FileAccessExtProxy::GetRoots(std::vector<RootInfo> &rootInfoVec)
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -544,7 +544,7 @@ int FileAccessExtProxy::GetRoots(std::vector<RootInfo> &rootInfoVec)
|
||||
if (!reply.ReadUint64(count)) {
|
||||
HILOG_ERROR("GetRoots operation failed to Read count");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_RESULT;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
rootInfoVec.clear();
|
||||
@ -566,13 +566,13 @@ int FileAccessExtProxy::UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo)
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&selectFile)) {
|
||||
HILOG_ERROR("fail to WriteParcelable selectFile");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -584,11 +584,11 @@ int FileAccessExtProxy::UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo)
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -601,7 +601,7 @@ int FileAccessExtProxy::UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo)
|
||||
if (fileInfoTemp == nullptr) {
|
||||
HILOG_ERROR("ReadParcelable value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
fileInfo = *fileInfoTemp;
|
||||
@ -616,13 +616,13 @@ int FileAccessExtProxy::Access(const Uri &uri, bool &isExist)
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&uri)) {
|
||||
HILOG_ERROR("fail to WriteParcelable uri");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -634,11 +634,11 @@ int FileAccessExtProxy::Access(const Uri &uri, bool &isExist)
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -650,7 +650,7 @@ int FileAccessExtProxy::Access(const Uri &uri, bool &isExist)
|
||||
if (!reply.ReadBool(isExist)) {
|
||||
HILOG_ERROR("fail to ReadInt32 isExist");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -664,13 +664,13 @@ int FileAccessExtProxy::RegisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(notify->AsObject())) {
|
||||
HILOG_ERROR("write subscribe type or parcel failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -682,11 +682,11 @@ int FileAccessExtProxy::RegisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
@ -705,13 +705,13 @@ int FileAccessExtProxy::UnregisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
if (!data.WriteInterfaceToken(FileAccessExtProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("WriteInterfaceToken failed");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(notify->AsObject())) {
|
||||
HILOG_ERROR("write subscribe type or parcel failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
@ -723,11 +723,11 @@ int FileAccessExtProxy::UnregisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
return err;
|
||||
}
|
||||
|
||||
int ret = ERR_PARCEL_FAIL;
|
||||
int ret = E_IPCS;
|
||||
if (!reply.ReadInt32(ret)) {
|
||||
HILOG_ERROR("fail to ReadInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
|
@ -67,7 +67,7 @@ int FileAccessExtStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa
|
||||
if (!CheckCallingPermission(FILE_ACCESS_PERMISSION)) {
|
||||
HILOG_ERROR("permission error");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PERMISSION_DENIED;
|
||||
return E_PERMISSION;
|
||||
}
|
||||
|
||||
std::u16string descriptor = FileAccessExtStub::GetDescriptor();
|
||||
@ -94,20 +94,20 @@ ErrCode FileAccessExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply
|
||||
if (uri == nullptr) {
|
||||
HILOG_ERROR("Parameter OpenFile fail to ReadParcelable uri");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int flags = ERR_PARCEL_FAIL;
|
||||
int flags = E_IPCS;
|
||||
if (!data.ReadInt32(flags)) {
|
||||
HILOG_ERROR("Parameter OpenFile fail to ReadInt32 flags");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (flags < 0) {
|
||||
HILOG_ERROR("Parameter OpenFile flags is invalid");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
int fd = -1;
|
||||
@ -115,13 +115,13 @@ ErrCode FileAccessExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter OpenFile fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.WriteFileDescriptor(fd)) {
|
||||
HILOG_ERROR("Parameter OpenFile fail to WriteFileDescriptor fd");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -135,20 +135,20 @@ ErrCode FileAccessExtStub::CmdCreateFile(MessageParcel &data, MessageParcel &rep
|
||||
if (parent == nullptr) {
|
||||
HILOG_ERROR("Parameter CreateFile fail to ReadParcelable parent");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::string displayName = "";
|
||||
if (!data.ReadString(displayName)) {
|
||||
HILOG_ERROR("Parameter CreateFile fail to ReadString displayName");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (displayName.empty()) {
|
||||
HILOG_ERROR("Parameter CreateFile displayName is empty");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
std::string newFile = "";
|
||||
@ -157,13 +157,13 @@ ErrCode FileAccessExtStub::CmdCreateFile(MessageParcel &data, MessageParcel &rep
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter CreateFile fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.WriteParcelable(&newFileUri)) {
|
||||
HILOG_ERROR("Parameter CreateFile fail to WriteParcelable newFileUri");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -177,20 +177,20 @@ ErrCode FileAccessExtStub::CmdMkdir(MessageParcel &data, MessageParcel &reply)
|
||||
if (parent == nullptr) {
|
||||
HILOG_ERROR("Parameter Mkdir fail to ReadParcelable parent");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::string displayName = "";
|
||||
if (!data.ReadString(displayName)) {
|
||||
HILOG_ERROR("Parameter Mkdir fail to ReadString displayName");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (displayName.empty()) {
|
||||
HILOG_ERROR("Parameter Mkdir displayName is empty");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
std::string newFile = "";
|
||||
@ -199,13 +199,13 @@ ErrCode FileAccessExtStub::CmdMkdir(MessageParcel &data, MessageParcel &reply)
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter Mkdir fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.WriteParcelable(&newFileUri)) {
|
||||
HILOG_ERROR("Parameter Mkdir fail to WriteParcelable newFileUri");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -219,14 +219,14 @@ ErrCode FileAccessExtStub::CmdDelete(MessageParcel &data, MessageParcel &reply)
|
||||
if (uri == nullptr) {
|
||||
HILOG_ERROR("Parameter Delete fail to ReadParcelable uri");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = Delete(*uri);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter Delete fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -240,14 +240,14 @@ ErrCode FileAccessExtStub::CmdMove(MessageParcel &data, MessageParcel &reply)
|
||||
if (sourceFile == nullptr) {
|
||||
HILOG_ERROR("Parameter Move fail to ReadParcelable sourceFile");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::shared_ptr<Uri> targetParent(data.ReadParcelable<Uri>());
|
||||
if (targetParent == nullptr) {
|
||||
HILOG_ERROR("Parameter Move fail to ReadParcelable targetParent");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::string newFile = "";
|
||||
@ -256,13 +256,13 @@ ErrCode FileAccessExtStub::CmdMove(MessageParcel &data, MessageParcel &reply)
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter Move fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.WriteParcelable(&newFileUri)) {
|
||||
HILOG_ERROR("Parameter Move fail to WriteParcelable newFileUri");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -276,20 +276,20 @@ ErrCode FileAccessExtStub::CmdRename(MessageParcel &data, MessageParcel &reply)
|
||||
if (sourceFile == nullptr) {
|
||||
HILOG_ERROR("Parameter Rename fail to ReadParcelable sourceFile");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::string displayName = "";
|
||||
if (!data.ReadString(displayName)) {
|
||||
HILOG_ERROR("Parameter Rename fail to ReadString displayName");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (displayName.empty()) {
|
||||
HILOG_ERROR("Parameter Rename displayName is empty");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
std::string newFile = "";
|
||||
@ -298,13 +298,13 @@ ErrCode FileAccessExtStub::CmdRename(MessageParcel &data, MessageParcel &reply)
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter Rename fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.WriteParcelable(&newFileUri)) {
|
||||
HILOG_ERROR("Parameter Rename fail to WriteParcelable newFileUri");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -318,28 +318,28 @@ ErrCode FileAccessExtStub::CmdListFile(MessageParcel &data, MessageParcel &reply
|
||||
if (fileInfo == nullptr) {
|
||||
HILOG_ERROR("Parameter ListFile fail to ReadParcelable fileInfo");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t offset = 0;
|
||||
if (!data.ReadInt64(offset)) {
|
||||
HILOG_ERROR("parameter ListFile offset is invalid");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t maxCount = 0;
|
||||
if (!data.ReadInt64(maxCount)) {
|
||||
HILOG_ERROR("parameter ListFile maxCount is invalid");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::shared_ptr<FileFilter> filter(data.ReadParcelable<FileFilter>());
|
||||
if (filter == nullptr) {
|
||||
HILOG_ERROR("parameter ListFile FileFilter is invalid");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
@ -347,21 +347,21 @@ ErrCode FileAccessExtStub::CmdListFile(MessageParcel &data, MessageParcel &reply
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter ListFile fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t count {fileInfoVec.size()};
|
||||
if (!reply.WriteInt64(count)) {
|
||||
HILOG_ERROR("Parameter ListFile fail to WriteInt64 count");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
for (const auto &fileInfo : fileInfoVec) {
|
||||
if (!reply.WriteParcelable(&fileInfo)) {
|
||||
HILOG_ERROR("parameter ListFile fail to WriteParcelable fileInfoVec");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,28 +376,28 @@ ErrCode FileAccessExtStub::CmdScanFile(MessageParcel &data, MessageParcel &reply
|
||||
if (fileInfo == nullptr) {
|
||||
HILOG_ERROR("Parameter ScanFile fail to ReadParcelable fileInfo");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t offset = 0;
|
||||
if (!data.ReadInt64(offset)) {
|
||||
HILOG_ERROR("parameter ScanFile offset is invalid");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t maxCount = 0;
|
||||
if (!data.ReadInt64(maxCount)) {
|
||||
HILOG_ERROR("parameter ScanFile maxCount is invalid");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::shared_ptr<FileFilter> filter(data.ReadParcelable<FileFilter>());
|
||||
if (filter == nullptr) {
|
||||
HILOG_ERROR("parameter ScanFile FileFilter is invalid");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
@ -405,21 +405,21 @@ ErrCode FileAccessExtStub::CmdScanFile(MessageParcel &data, MessageParcel &reply
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter ScanFile fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t count {fileInfoVec.size()};
|
||||
if (!reply.WriteInt64(count)) {
|
||||
HILOG_ERROR("Parameter ScanFile fail to WriteInt64 count");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
for (const auto &fileInfo : fileInfoVec) {
|
||||
if (!reply.WriteParcelable(&fileInfo)) {
|
||||
HILOG_ERROR("parameter ScanFile fail to WriteParcelable fileInfoVec");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -436,21 +436,21 @@ ErrCode FileAccessExtStub::CmdGetRoots(MessageParcel &data, MessageParcel &reply
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter GetRoots fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int64_t count {rootInfoVec.size()};
|
||||
if (!reply.WriteInt64(count)) {
|
||||
HILOG_ERROR("Parameter GetRoots fail to WriteInt64 count");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
for (const auto &rootInfo : rootInfoVec) {
|
||||
if (!reply.WriteParcelable(&rootInfo)) {
|
||||
HILOG_ERROR("parameter ListFile fail to WriteParcelable rootInfo");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,7 +465,7 @@ ErrCode FileAccessExtStub::CmdUriToFileInfo(MessageParcel &data, MessageParcel &
|
||||
if (uri == nullptr) {
|
||||
HILOG_ERROR("SelectFile uri is nullptr");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
FileInfo fileInfoTemp;
|
||||
@ -473,13 +473,13 @@ ErrCode FileAccessExtStub::CmdUriToFileInfo(MessageParcel &data, MessageParcel &
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter UriToFileInfo fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.WriteParcelable(&fileInfoTemp)) {
|
||||
HILOG_ERROR("Parameter UriToFileInfo fail to WriteParcelable fileInfoTemp");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -493,7 +493,7 @@ ErrCode FileAccessExtStub::CmdAccess(MessageParcel &data, MessageParcel &reply)
|
||||
if (uri == nullptr) {
|
||||
HILOG_ERROR("Access uri is nullptr");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
bool isExist = false;
|
||||
@ -501,13 +501,13 @@ ErrCode FileAccessExtStub::CmdAccess(MessageParcel &data, MessageParcel &reply)
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter Access fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!reply.WriteBool(isExist)) {
|
||||
HILOG_ERROR("Parameter Access fail to WriteBool isExist");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -536,21 +536,21 @@ ErrCode FileAccessExtStub::CmdRegisterNotify(MessageParcel &data, MessageParcel
|
||||
if (remote == nullptr) {
|
||||
HILOG_INFO("get remote obj fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
auto notify = iface_cast<IFileAccessNotify>(remote);
|
||||
if (notify == nullptr) {
|
||||
HILOG_INFO("get notify fail");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = RegisterNotify(notify);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter RegisterNotify fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_OK;
|
||||
@ -563,21 +563,21 @@ ErrCode FileAccessExtStub::CmdUnregisterNotify(MessageParcel &data, MessageParce
|
||||
if (remote == nullptr) {
|
||||
HILOG_INFO("get remote obj fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
auto notify = iface_cast<IFileAccessNotify>(remote);
|
||||
if (notify == nullptr) {
|
||||
HILOG_INFO("get notify fail");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = UnregisterNotify(notify);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("Parameter UnregisterNotify fail to WriteInt32 ret");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_OK;
|
||||
|
@ -34,7 +34,7 @@ int FileAccessExtStubImpl::OpenFile(const Uri &uri, const int flags, int &fd)
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("OpenFile get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->OpenFile(uri, flags, fd);
|
||||
@ -48,7 +48,7 @@ int FileAccessExtStubImpl::CreateFile(const Uri &parent, const std::string &disp
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("CreateFile get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->CreateFile(parent, displayName, newFile);
|
||||
@ -62,7 +62,7 @@ int FileAccessExtStubImpl::Mkdir(const Uri &parent, const std::string &displayNa
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("Mkdir get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->Mkdir(parent, displayName, newFile);
|
||||
@ -76,7 +76,7 @@ int FileAccessExtStubImpl::Delete(const Uri &sourceFile)
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("Delete get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->Delete(sourceFile);
|
||||
@ -90,7 +90,7 @@ int FileAccessExtStubImpl::Move(const Uri &sourceFile, const Uri &targetParent,
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("Move get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->Move(sourceFile, targetParent, newFile);
|
||||
@ -104,7 +104,7 @@ int FileAccessExtStubImpl::Rename(const Uri &sourceFile, const std::string &disp
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("Rename get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->Rename(sourceFile, displayName, newFile);
|
||||
@ -119,7 +119,7 @@ int FileAccessExtStubImpl::ListFile(const FileInfo &fileInfo, const int64_t offs
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("ListFile get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
@ -134,7 +134,7 @@ int FileAccessExtStubImpl::ScanFile(const FileInfo &fileInfo, const int64_t offs
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("ScanFile get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
@ -148,7 +148,7 @@ int FileAccessExtStubImpl::GetRoots(std::vector<RootInfo> &rootInfoVec)
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("GetRoots get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->GetRoots(rootInfoVec);
|
||||
@ -162,7 +162,7 @@ int FileAccessExtStubImpl::UriToFileInfo(const Uri &selectFile, FileInfo &fileIn
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("UriToFileInfo get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->UriToFileInfo(selectFile, fileInfo);
|
||||
@ -176,7 +176,7 @@ int FileAccessExtStubImpl::Access(const Uri &uri, bool &isExist)
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("Access get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension_->Access(uri, isExist);
|
||||
@ -191,7 +191,7 @@ int FileAccessExtStubImpl::RegisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
if (extension == nullptr) {
|
||||
HILOG_ERROR("get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension->RegisterNotify(notify);
|
||||
@ -209,7 +209,7 @@ int FileAccessExtStubImpl::UnregisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
if (extension == nullptr) {
|
||||
HILOG_ERROR("get extension failed.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = extension->UnregisterNotify(notify);
|
||||
|
@ -150,17 +150,17 @@ static bool IsSystemApp()
|
||||
return OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(accessTokenIDEx);
|
||||
}
|
||||
|
||||
std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
std::pair<std::shared_ptr<FileAccessHelper>, int> FileAccessHelper::Creator(
|
||||
const std::shared_ptr<OHOS::AbilityRuntime::Context> &context)
|
||||
{
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("FileAccessHelper::Creator failed, context == nullptr");
|
||||
return nullptr;
|
||||
return {nullptr, EINVAL};
|
||||
}
|
||||
|
||||
if (!IsSystemApp()) {
|
||||
HILOG_ERROR("FileAccessHelper::Creator check IsSystemAppByFullTokenID failed");
|
||||
return nullptr;
|
||||
return {nullptr, E_PERMISSION_SYS};
|
||||
}
|
||||
|
||||
sptr<AppExecFwk::IBundleMgr> bm = FileAccessHelper::GetBundleMgrProxy();
|
||||
@ -171,7 +171,7 @@ std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION, GetUserId(), extensionInfos);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("FileAccessHelper::Creator QueryExtensionAbilityInfos failed");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETINFO};
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < extensionInfos.size(); i++) {
|
||||
@ -180,7 +180,7 @@ std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
sptr<FileAccessExtConnection> fileAccessExtConnection = new(std::nothrow) FileAccessExtConnection();
|
||||
if (fileAccessExtConnection == nullptr) {
|
||||
HILOG_ERROR("new fileAccessExtConnection fail");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETRESULT};
|
||||
}
|
||||
|
||||
if (!fileAccessExtConnection->IsExtAbilityConnected()) {
|
||||
@ -190,13 +190,13 @@ std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
sptr<IFileAccessExtBase> fileExtProxy = fileAccessExtConnection->GetFileExtProxy();
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("Creator get invalid fileExtProxy");
|
||||
return nullptr;
|
||||
return {nullptr, E_CONNECT};
|
||||
}
|
||||
|
||||
std::shared_ptr<ConnectInfo> connectInfo = std::make_shared<ConnectInfo>();
|
||||
if (connectInfo == nullptr) {
|
||||
HILOG_ERROR("Creator, connectInfo == nullptr");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETRESULT};
|
||||
}
|
||||
FileAccessHelper::wants_.push_back(wantTem);
|
||||
|
||||
@ -207,33 +207,33 @@ std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
FileAccessHelper *ptrFileAccessHelper = new (std::nothrow) FileAccessHelper(context, cMap);
|
||||
if (ptrFileAccessHelper == nullptr) {
|
||||
HILOG_ERROR("FileAccessHelper::Creator failed, create FileAccessHelper failed");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETRESULT};
|
||||
}
|
||||
|
||||
return std::shared_ptr<FileAccessHelper>(ptrFileAccessHelper);
|
||||
return {std::shared_ptr<FileAccessHelper>(ptrFileAccessHelper), ERR_OK};
|
||||
}
|
||||
|
||||
std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
std::pair<std::shared_ptr<FileAccessHelper>, int> FileAccessHelper::Creator(
|
||||
const std::shared_ptr<OHOS::AbilityRuntime::Context> &context, const std::vector<AAFwk::Want> &wants)
|
||||
{
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("FileAccessHelper::Creator failed, context == nullptr");
|
||||
return nullptr;
|
||||
return {nullptr, EINVAL};
|
||||
}
|
||||
|
||||
if (wants.size() == 0) {
|
||||
HILOG_ERROR("FileAccessHelper::Creator failed, wants is empty");
|
||||
return nullptr;
|
||||
return {nullptr, EINVAL};
|
||||
}
|
||||
|
||||
if (!IsSystemApp()) {
|
||||
HILOG_ERROR("FileAccessHelper::Creator check IsSystemAppByFullTokenID failed");
|
||||
return nullptr;
|
||||
return {nullptr, E_PERMISSION_SYS};
|
||||
}
|
||||
|
||||
if (GetRegisteredFileAccessExtAbilityInfo(FileAccessHelper::wants_) != ERR_OK) {
|
||||
HILOG_ERROR("GetRegisteredFileAccessExtAbilityInfo failed");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETINFO};
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<ConnectInfo>> cMap;
|
||||
@ -241,7 +241,7 @@ std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
sptr<FileAccessExtConnection> fileAccessExtConnection = new(std::nothrow) FileAccessExtConnection();
|
||||
if (fileAccessExtConnection == nullptr) {
|
||||
HILOG_ERROR("new fileAccessExtConnection fail");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETRESULT};
|
||||
}
|
||||
|
||||
if (!fileAccessExtConnection->IsExtAbilityConnected()) {
|
||||
@ -251,13 +251,13 @@ std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
sptr<IFileAccessExtBase> fileExtProxy = fileAccessExtConnection->GetFileExtProxy();
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("Creator get invalid fileExtProxy");
|
||||
return nullptr;
|
||||
return {nullptr, E_CONNECT};
|
||||
}
|
||||
|
||||
std::shared_ptr<ConnectInfo> connectInfo = std::make_shared<ConnectInfo>();
|
||||
if (connectInfo == nullptr) {
|
||||
HILOG_ERROR("Creator, connectInfo == nullptr");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETRESULT};
|
||||
}
|
||||
|
||||
connectInfo->want = wants[i];
|
||||
@ -265,17 +265,17 @@ std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(
|
||||
string bundleName = FileAccessHelper::GetKeyOfWants(wants[i]);
|
||||
if (bundleName.length() == 0) {
|
||||
HILOG_ERROR("Creator GetKeyOfWants bundleName not found");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETRESULT};
|
||||
}
|
||||
cMap.insert(std::pair<std::string, std::shared_ptr<ConnectInfo>>(bundleName, connectInfo));
|
||||
}
|
||||
FileAccessHelper *ptrFileAccessHelper = new (std::nothrow) FileAccessHelper(context, cMap);
|
||||
if (ptrFileAccessHelper == nullptr) {
|
||||
HILOG_ERROR("Creator failed, create FileAccessHelper failed");
|
||||
return nullptr;
|
||||
return {nullptr, E_GETRESULT};
|
||||
}
|
||||
|
||||
return std::shared_ptr<FileAccessHelper>(ptrFileAccessHelper);
|
||||
return {std::shared_ptr<FileAccessHelper>(ptrFileAccessHelper), ERR_OK};
|
||||
}
|
||||
|
||||
std::shared_ptr<FileAccessHelper> FileAccessHelper::Creator(const sptr<IRemoteObject> &token,
|
||||
@ -419,20 +419,20 @@ int FileAccessHelper::OpenFile(Uri &uri, int flags, int &fd)
|
||||
if (!CheckUri(uri)) {
|
||||
HILOG_ERROR("Uri format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
if (flags != READ && flags != WRITE && flags != WRITE_READ) {
|
||||
HILOG_ERROR("flags type error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(uri);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->OpenFile(uri, flags, fd);
|
||||
@ -457,14 +457,14 @@ int FileAccessHelper::CreateFile(Uri &parent, const std::string &displayName, Ur
|
||||
if (!CheckUri(parent)) {
|
||||
HILOG_ERROR("Uri format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(parent);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->CreateFile(parent, displayName, newFile);
|
||||
@ -489,14 +489,14 @@ int FileAccessHelper::Mkdir(Uri &parent, const std::string &displayName, Uri &ne
|
||||
if (!CheckUri(parent)) {
|
||||
HILOG_ERROR("Uri format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(parent);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->Mkdir(parent, displayName, newDir);
|
||||
@ -521,14 +521,14 @@ int FileAccessHelper::Delete(Uri &selectFile)
|
||||
if (!CheckUri(selectFile)) {
|
||||
HILOG_ERROR("Uri format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(selectFile);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->Delete(selectFile);
|
||||
@ -555,26 +555,26 @@ int FileAccessHelper::Move(Uri &sourceFile, Uri &targetParent, Uri &newFile)
|
||||
if (!CheckUri(sourceFile)) {
|
||||
HILOG_ERROR("sourceFile format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
if (!CheckUri(targetParent)) {
|
||||
HILOG_ERROR("targetParent format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
if (sourceFileUri.GetScheme() != targetParentUri.GetScheme()) {
|
||||
HILOG_WARN("Operation failed, move not supported");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_OPERATION_NOT_SUPPORT;
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(sourceFile);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->Move(sourceFile, targetParent, newFile);
|
||||
@ -599,14 +599,14 @@ int FileAccessHelper::Rename(Uri &sourceFile, const std::string &displayName, Ur
|
||||
if (!CheckUri(sourceFile)) {
|
||||
HILOG_ERROR("sourceFile format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(sourceFile);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->Rename(sourceFile, displayName, newFile);
|
||||
@ -633,14 +633,14 @@ int FileAccessHelper::ListFile(const FileInfo &fileInfo, const int64_t offset, c
|
||||
if (!CheckUri(sourceFile)) {
|
||||
HILOG_ERROR("sourceFile format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(sourceFile);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
@ -667,14 +667,14 @@ int FileAccessHelper::ScanFile(const FileInfo &fileInfo, const int64_t offset, c
|
||||
if (!CheckUri(sourceFile)) {
|
||||
HILOG_ERROR("sourceFile format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(sourceFile);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
@ -699,7 +699,7 @@ int FileAccessHelper::GetRoots(std::vector<RootInfo> &rootInfoVec)
|
||||
if (!GetProxy()) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = ERR_OK;
|
||||
@ -741,14 +741,14 @@ int FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(std::vector<AAFwk::W
|
||||
if (bm == nullptr) {
|
||||
HILOG_ERROR("GetBundleMgrProxy nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_QUERY_EXTENSIONINFOS_FAIL;
|
||||
return E_GETINFO;
|
||||
}
|
||||
bool ret = bm->QueryExtensionAbilityInfos(
|
||||
AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION, GetUserId(), extensionInfos);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo QueryExtensionAbilityInfos error");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_QUERY_EXTENSIONINFOS_FAIL;
|
||||
return E_GETINFO;
|
||||
}
|
||||
|
||||
wantVec.clear();
|
||||
@ -773,14 +773,14 @@ int FileAccessHelper::Access(Uri &uri, bool &isExist)
|
||||
if (!CheckUri(uri)) {
|
||||
HILOG_ERROR("uri format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(uri);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->Access(uri, isExist);
|
||||
@ -805,14 +805,14 @@ int FileAccessHelper::UriToFileInfo(Uri &selectFile, FileInfo &fileInfo)
|
||||
if (!CheckUri(selectFile)) {
|
||||
HILOG_ERROR("selectFile uri format check error.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_URI;
|
||||
return E_URIS;
|
||||
}
|
||||
|
||||
sptr<IFileAccessExtBase> fileExtProxy = GetProxyByUri(selectFile);
|
||||
if (fileExtProxy == nullptr) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int ret = fileExtProxy->UriToFileInfo(selectFile, fileInfo);
|
||||
@ -832,13 +832,13 @@ int FileAccessHelper::On(std::shared_ptr<INotifyCallback> &callback)
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("failed with invalid callback");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (!GetProxy()) {
|
||||
HILOG_ERROR("failed with invalid fileAccessExtProxy");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(notifyAgentMutex_);
|
||||
@ -847,7 +847,7 @@ int FileAccessHelper::On(std::shared_ptr<INotifyCallback> &callback)
|
||||
if (notifyAgent_ == nullptr) {
|
||||
HILOG_ERROR("new FileAccessNotifyAgent fail");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -858,7 +858,7 @@ int FileAccessHelper::On(std::shared_ptr<INotifyCallback> &callback)
|
||||
if (fileAccessExtProxy == nullptr) {
|
||||
HILOG_ERROR("fileAccessExtProxy RegisterNotify fail");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
errorCode = fileAccessExtProxy->RegisterNotify(notifyAgent_);
|
||||
@ -881,7 +881,7 @@ int FileAccessHelper::Off()
|
||||
if (notifyAgent_ == nullptr) {
|
||||
HILOG_ERROR("not registered notify");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NOTIFY_NOT_EXIST;
|
||||
return E_NOTIFY;
|
||||
}
|
||||
|
||||
int errorCode = ERR_OK;
|
||||
|
@ -221,7 +221,7 @@ static int DoCallJsMethod(CallJsParam *param)
|
||||
if (jsRuntime == nullptr) {
|
||||
HILOG_ERROR("failed to get jsRuntime.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
HandleEscape handleEscape(*jsRuntime);
|
||||
auto& nativeEngine = jsRuntime->GetNativeEngine();
|
||||
@ -231,36 +231,36 @@ static int DoCallJsMethod(CallJsParam *param)
|
||||
if (!param->argParser(nativeEngine, argv, argc)) {
|
||||
HILOG_ERROR("failed to get params.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
NativeValue *value = param->jsObj->Get();
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("failed to get native value object.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
NativeObject *obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("failed to get FileExtAbility object.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
NativeValue *method = obj->GetProperty(param->funcName.c_str());
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("failed to get %{public}s from FileExtAbility object.", param->funcName.c_str());
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
if (param->retParser == nullptr) {
|
||||
HILOG_ERROR("ResultValueParser must not null.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
if (!param->retParser(nativeEngine, handleEscape.Escape(nativeEngine.CallFunction(value, method, argv, argc)))) {
|
||||
HILOG_INFO("Parser js result fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARSER_FAIL;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_OK;
|
||||
@ -275,19 +275,19 @@ int JsFileAccessExtAbility::CallJsMethod(const std::string &funcName, JsRuntime
|
||||
if (status != napi_ok) {
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
HILOG_ERROR("failed to get uv event loop.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
auto param = std::make_shared<CallJsParam>(funcName, &jsRuntime, jsObj, argParser, retParser);
|
||||
if (param == nullptr) {
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
HILOG_ERROR("failed to new param.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
auto work = std::make_shared<uv_work_t>();
|
||||
if (work == nullptr) {
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
HILOG_ERROR("failed to new uv_work_t.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
work->data = reinterpret_cast<void *>(param.get());
|
||||
int ret = uv_queue_work(loop, work.get(), [](uv_work_t *work) {}, [](uv_work_t *work, int status) {
|
||||
@ -308,7 +308,7 @@ int JsFileAccessExtAbility::CallJsMethod(const std::string &funcName, JsRuntime
|
||||
if (ret != 0) {
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
HILOG_ERROR("failed to exec uv_queue_work.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(param->fileOperateMutex);
|
||||
param->fileOperateCondition.wait(lock, [param]() { return param->isReady; });
|
||||
@ -354,7 +354,7 @@ int JsFileAccessExtAbility::OpenFile(const Uri &uri, int flags, int &fd)
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("OpenFile value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser = [uri, flags](NativeEngine &engine, NativeValue *argv[], size_t &argc) -> bool {
|
||||
@ -394,14 +394,14 @@ int JsFileAccessExtAbility::OpenFile(const Uri &uri, int flags, int &fd)
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
fd = value->data;
|
||||
if (fd < ERR_OK) {
|
||||
HILOG_ERROR("Failed to get file descriptor fd: %{public}d", fd);
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_OK;
|
||||
@ -414,7 +414,7 @@ int JsFileAccessExtAbility::CreateFile(const Uri &parent, const std::string &dis
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("CreateFile value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser = [parent, displayName](NativeEngine &engine, NativeValue *argv[], size_t &argc) -> bool {
|
||||
@ -454,13 +454,13 @@ int JsFileAccessExtAbility::CreateFile(const Uri &parent, const std::string &dis
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
if ((value->data).empty()) {
|
||||
HILOG_ERROR("call CreateFile with return empty.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARSER_FAIL;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
newFile = Uri(value->data);
|
||||
@ -475,7 +475,7 @@ int JsFileAccessExtAbility::Mkdir(const Uri &parent, const std::string &displayN
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Mkdir value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser = [parent, displayName](NativeEngine &engine, NativeValue *argv[], size_t &argc) -> bool {
|
||||
@ -516,13 +516,13 @@ int JsFileAccessExtAbility::Mkdir(const Uri &parent, const std::string &displayN
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
if ((value->data).empty()) {
|
||||
HILOG_ERROR("call Mkdir with return empty.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARSER_FAIL;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
newFile = Uri(value->data);
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -536,7 +536,7 @@ int JsFileAccessExtAbility::Delete(const Uri &sourceFile)
|
||||
if (ret == nullptr) {
|
||||
HILOG_ERROR("Delete value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser = [uri = sourceFile](NativeEngine &engine, NativeValue *argv[], size_t &argc) -> bool {
|
||||
@ -567,7 +567,7 @@ int JsFileAccessExtAbility::Delete(const Uri &sourceFile)
|
||||
if (*ret != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return *ret;
|
||||
}
|
||||
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -581,7 +581,7 @@ int JsFileAccessExtAbility::Move(const Uri &sourceFile, const Uri &targetParent,
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Move value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser = [sourceFile, targetParent](NativeEngine &engine, NativeValue* argv[], size_t &argc) -> bool {
|
||||
@ -622,13 +622,13 @@ int JsFileAccessExtAbility::Move(const Uri &sourceFile, const Uri &targetParent,
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
if ((value->data).empty()) {
|
||||
HILOG_ERROR("call move with return empty.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARSER_FAIL;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
newFile = Uri(value->data);
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -642,7 +642,7 @@ int JsFileAccessExtAbility::Rename(const Uri &sourceFile, const std::string &dis
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Rename value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
auto argParser = [sourceFile, displayName](NativeEngine &engine, NativeValue *argv[], size_t &argc) -> bool {
|
||||
NativeValue *nativeSourceFile = engine.CreateString(sourceFile.ToString().c_str(),
|
||||
@ -682,13 +682,13 @@ int JsFileAccessExtAbility::Rename(const Uri &sourceFile, const std::string &dis
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
if ((value->data).empty()) {
|
||||
HILOG_ERROR("call Rename with return empty.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_PARSER_FAIL;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
newFile = Uri(value->data);
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
@ -746,7 +746,7 @@ static int MakeStringNativeArray(NativeEngine &engine, std::vector<std::string>
|
||||
NativeArray *nativeArray = ConvertNativeValueTo<NativeArray>(resultArray);
|
||||
if (nativeArray == nullptr) {
|
||||
HILOG_ERROR("Create NativeArray nullptr");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
@ -754,13 +754,13 @@ static int MakeStringNativeArray(NativeEngine &engine, std::vector<std::string>
|
||||
NativeValue* nativeValue = engine.CreateString(inputArray[i].c_str(), inputArray[i].length());
|
||||
if (nativeValue == nullptr) {
|
||||
HILOG_ERROR("Create NativeValue fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
ret = nativeArray->SetElement(i, nativeValue);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("Add NativeValue to NativeArray fail.");
|
||||
return ERR_PARCEL_FAIL;
|
||||
return E_IPCS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -772,13 +772,13 @@ static int MakeJsNativeFileFilter(NativeEngine &engine, const FileFilter &filter
|
||||
nativeFilter = engine.CreateObject();
|
||||
if (nativeFilter == nullptr) {
|
||||
HILOG_ERROR("Create js NativeValue fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
NativeValue *suffixArray = engine.CreateArray(filter.GetSuffix().size());
|
||||
if (suffixArray == nullptr) {
|
||||
HILOG_ERROR("Create Suffix native array value fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
std::vector<std::string> suffixVec = filter.GetSuffix();
|
||||
@ -791,7 +791,7 @@ static int MakeJsNativeFileFilter(NativeEngine &engine, const FileFilter &filter
|
||||
NativeValue *displayNameArray = engine.CreateArray(filter.GetDisplayName().size());
|
||||
if (displayNameArray == nullptr) {
|
||||
HILOG_ERROR("Create DisplayName native array value fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
std::vector<std::string> displayNameVec = filter.GetDisplayName();
|
||||
@ -804,7 +804,7 @@ static int MakeJsNativeFileFilter(NativeEngine &engine, const FileFilter &filter
|
||||
NativeValue *mimeTypeArray = engine.CreateArray(filter.GetMimeType().size());
|
||||
if (mimeTypeArray == nullptr) {
|
||||
HILOG_ERROR("Create MimeType native array value fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
std::vector<std::string> mimeTypeVec = filter.GetMimeType();
|
||||
@ -817,25 +817,25 @@ static int MakeJsNativeFileFilter(NativeEngine &engine, const FileFilter &filter
|
||||
NativeValue *nativeFileSizeOver = engine.CreateNumber(filter.GetFileSizeOver());
|
||||
if (nativeFileSizeOver == nullptr) {
|
||||
HILOG_ERROR("Create NativeFileSizeOver native js value fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
NativeValue *nativeLastModifiedAfter = engine.CreateNumber(filter.GetLastModifiedAfter());
|
||||
if (nativeLastModifiedAfter == nullptr) {
|
||||
HILOG_ERROR("Create NativeLastModifiedAfter native js value fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
NativeValue *nativeExcludeMedia = engine.CreateBoolean(filter.GetExcludeMedia());
|
||||
if (nativeExcludeMedia == nullptr) {
|
||||
HILOG_ERROR("Create NativeExcludeMedia native js value fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
NativeObject *objFilter = ConvertNativeValueTo<NativeObject>(nativeFilter);
|
||||
if (objFilter == nullptr) {
|
||||
HILOG_ERROR("Convert js object fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
bool ret = objFilter->SetProperty("suffix", suffixArray);
|
||||
@ -846,7 +846,7 @@ static int MakeJsNativeFileFilter(NativeEngine &engine, const FileFilter &filter
|
||||
ret = ret && objFilter->SetProperty("excludeMedia", nativeExcludeMedia);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("Set property to Filter NativeValue fail.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
@ -860,7 +860,7 @@ int JsFileAccessExtAbility::ListFile(const FileInfo &fileInfo, const int64_t off
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("ListFile value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser =
|
||||
@ -894,7 +894,7 @@ int JsFileAccessExtAbility::ListFile(const FileInfo &fileInfo, const int64_t off
|
||||
nativeFilter = engine.CreateNull();
|
||||
if (nativeFilter == nullptr) {
|
||||
HILOG_ERROR("Create js NativeValue fail.");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -927,7 +927,7 @@ int JsFileAccessExtAbility::ListFile(const FileInfo &fileInfo, const int64_t off
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
fileInfoVec = std::move(value->data);
|
||||
@ -986,7 +986,7 @@ int JsFileAccessExtAbility::GetRoots(std::vector<RootInfo> &rootInfoVec)
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("GetRoots value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser = [](NativeEngine &engine, NativeValue *argv[], size_t &argc) -> bool {
|
||||
@ -1015,7 +1015,7 @@ int JsFileAccessExtAbility::GetRoots(std::vector<RootInfo> &rootInfoVec)
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
rootInfoVec = std::move(value->data);
|
||||
@ -1030,7 +1030,7 @@ int JsFileAccessExtAbility::Access(const Uri &uri, bool &isExist)
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("Access value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser = [uri](NativeEngine &engine, NativeValue *argv[], size_t &argc) -> bool {
|
||||
@ -1043,7 +1043,7 @@ int JsFileAccessExtAbility::Access(const Uri &uri, bool &isExist)
|
||||
NativeObject *obj = ConvertNativeValueTo<NativeObject>(result);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Convert js object fail.");
|
||||
return ERR_PARSER_FAIL;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
bool ret = ConvertFromJsValue(engine, obj->GetProperty("isExist"), value->data);
|
||||
@ -1064,7 +1064,7 @@ int JsFileAccessExtAbility::Access(const Uri &uri, bool &isExist)
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
isExist = value->data;
|
||||
@ -1079,7 +1079,7 @@ int JsFileAccessExtAbility::UriToFileInfo(const Uri &selectFile, FileInfo &fileI
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("UriToFileInfo value is nullptr.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto argParser = [selectFile](NativeEngine &engine, NativeValue *argv[], size_t &argc) -> bool {
|
||||
@ -1135,7 +1135,7 @@ int JsFileAccessExtAbility::UriToFileInfo(const Uri &selectFile, FileInfo &fileI
|
||||
if (value->code != ERR_OK) {
|
||||
HILOG_ERROR("fileio fail.");
|
||||
FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
|
||||
return ERR_FILEIO_FAIL;
|
||||
return value->code;
|
||||
}
|
||||
|
||||
fileInfo = std::move(value->data);
|
||||
|
@ -34,7 +34,7 @@ int FileAccessNotifyManager::RegisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
{
|
||||
if (!AddNotifyToMap(notify)) {
|
||||
HILOG_ERROR("the remote obj is nullptr.");
|
||||
return ERR_INVALID_NOTIFY;
|
||||
return E_REGISTER;
|
||||
}
|
||||
HILOG_INFO("FileAccessNotifyManager::RegisterNotify success.");
|
||||
return ERR_OK;
|
||||
@ -44,12 +44,12 @@ int FileAccessNotifyManager::UnregisterNotify(sptr<IFileAccessNotify> ¬ify)
|
||||
{
|
||||
if (notify == nullptr || notify->AsObject() == nullptr) {
|
||||
HILOG_ERROR("the remote obj is nullptr.");
|
||||
return ERR_INVALID_NOTIFY;
|
||||
return E_NOTIFY;
|
||||
}
|
||||
|
||||
if (!RemoveNotifyFromMap(notify->AsObject())) {
|
||||
HILOG_ERROR("remove remote obj from map fail.");
|
||||
return ERR_REMOVE_NOTIFY_FAIL;
|
||||
return E_REMOVE;
|
||||
}
|
||||
HILOG_INFO("FileAccessNotifyManager::UnregisterNotify success.");
|
||||
return ERR_OK;
|
||||
|
@ -32,12 +32,12 @@ int FileAccessNotifyProxy::Notify(const NotifyMessage& message)
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(FileAccessNotifyProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("write descriptor failed");
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(&message)) {
|
||||
HILOG_ERROR("write parcel message failed");
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
|
||||
int error = Remote()->SendRequest(CMD_NOTIFY, data, reply, option);
|
||||
|
@ -28,7 +28,7 @@ int32_t FileAccessNotifyStub::OnRemoteRequest(uint32_t code, MessageParcel &data
|
||||
auto remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
HILOG_ERROR("local descriptor is not equal to remote");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
HILOG_INFO("FileAccessNotifyStub::OnRemoteRequest, code:%{public}u", code);
|
||||
switch (code) {
|
||||
@ -36,7 +36,7 @@ int32_t FileAccessNotifyStub::OnRemoteRequest(uint32_t code, MessageParcel &data
|
||||
std::shared_ptr<NotifyMessage> message(data.ReadParcelable<NotifyMessage>());
|
||||
if (message == nullptr) {
|
||||
HILOG_ERROR("read parcelable message fail");
|
||||
return ERR_IPC_ERROR;
|
||||
return E_IPCS;
|
||||
}
|
||||
auto ret = Notify(*message);
|
||||
if (ret != ERR_OK) {
|
||||
|
@ -176,7 +176,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_OpenFile_0001, testing::e
|
||||
Uri uri("");
|
||||
int fd;
|
||||
int result = g_fah->OpenFile(uri, WRITE_READ, fd);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0001 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_OpenFile_0001 occurs an exception.";
|
||||
@ -208,7 +208,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_OpenFile_0002, testing::e
|
||||
Uri uri("storage/media/100/local/files/Download/external_file_access_OpenFile_0002.txt");
|
||||
int fd;
|
||||
result = g_fah->OpenFile(uri, WRITE_READ, fd);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0002 result:" << result;
|
||||
result = g_fah->Delete(newFileUri);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -235,7 +235,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_OpenFile_0003, testing::e
|
||||
Uri uri("~!@#$%^&*()_");
|
||||
int fd;
|
||||
int result = g_fah->OpenFile(uri, WRITE_READ, fd);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0003 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_OpenFile_0003 occurs an exception.";
|
||||
@ -267,7 +267,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_OpenFile_0004, testing::e
|
||||
int fd;
|
||||
int flag = -1;
|
||||
result = g_fah->OpenFile(newFileUri, flag, fd);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0004 result:" << result;
|
||||
result = g_fah->Delete(newFileUri);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -485,7 +485,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_OpenFile_0009, testing::e
|
||||
int fd;
|
||||
Uri newFileUri(str + "/NotExistFile.txt");
|
||||
result = g_fah->OpenFile(newFileUri, WRITE_READ, fd);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0009 result:" << result;
|
||||
}
|
||||
} catch (...) {
|
||||
@ -703,7 +703,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_CreateFile_0006, testing:
|
||||
Uri newFileUri("");
|
||||
string displayName = "test.txt";
|
||||
result = g_fah->CreateFile(parentUri, displayName, newFileUri);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
GTEST_LOG_(INFO) << "CreateFile_0006 result:" << result;
|
||||
}
|
||||
} catch (...) {
|
||||
@ -921,7 +921,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Mkdir_0006, testing::ext:
|
||||
Uri newDirUriTest("");
|
||||
string displayName = "";
|
||||
result = g_fah->Mkdir(parentUri, displayName, newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
GTEST_LOG_(INFO) << "Mkdir_0006 result:" << result;
|
||||
}
|
||||
} catch (...) {
|
||||
@ -1012,7 +1012,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Delete_0002, testing::ext
|
||||
try {
|
||||
Uri selectFileUri("");
|
||||
int result = g_fah->Delete(selectFileUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Delete_0002 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_Delete_0002 occurs an exception.";
|
||||
@ -1043,7 +1043,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Delete_0003, testing::ext
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
Uri selectFileUri("storage/media/100/local/files/Download/test");
|
||||
result = g_fah->Delete(selectFileUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Delete_0003 result:" << result;
|
||||
@ -1069,7 +1069,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Delete_0004, testing::ext
|
||||
try {
|
||||
Uri selectFileUri("!@#$%^&*()");
|
||||
int result = g_fah->Delete(selectFileUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Delete_0004 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_Delete_0004 occurs an exception.";
|
||||
@ -1154,7 +1154,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Delete_0006, testing::ext
|
||||
}
|
||||
Uri selectFileUri(str);
|
||||
int result = g_fah->Delete(selectFileUri);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
GTEST_LOG_(INFO) << "Delete_0006 result:" << result;
|
||||
}
|
||||
} catch (...) {
|
||||
@ -1269,7 +1269,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Move_0002, testing::ext::
|
||||
Uri testUri("");
|
||||
Uri sourceFileUri("");
|
||||
result = g_fah->Move(sourceFileUri, newDirUriTest, testUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0002 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1310,7 +1310,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Move_0003, testing::ext::
|
||||
Uri testUri2("");
|
||||
Uri sourceFileUri("storage/media/100/local/files/Download/test1/test.txt");
|
||||
result = g_fah->Move(sourceFileUri, newDirUriTest2, testUri2);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0003 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest1);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1347,7 +1347,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Move_0004, testing::ext::
|
||||
Uri testUri("");
|
||||
Uri sourceFileUri("~!@#$%^&*()_");
|
||||
result = g_fah->Move(sourceFileUri, newDirUriTest, testUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0004 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1385,7 +1385,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Move_0005, testing::ext::
|
||||
Uri testUri2("");
|
||||
Uri targetParentUri("");
|
||||
result = g_fah->Move(testUri, targetParentUri, testUri2);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0005 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1426,7 +1426,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Move_0006, testing::ext::
|
||||
Uri testUri2("");
|
||||
Uri targetParentUri("storage/media/100/local/files/Download/test2");
|
||||
result = g_fah->Move(testUri, targetParentUri, testUri2);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0006 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest1);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1469,7 +1469,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Move_0007, testing::ext::
|
||||
Uri testUri2("");
|
||||
Uri targetParentUri("~!@#$^%&*()_");
|
||||
result = g_fah->Move(testUri, targetParentUri, testUri2);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0007 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest1);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1747,7 +1747,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Move_0013, testing::ext::
|
||||
Uri uri(str);
|
||||
Uri testUri2("");
|
||||
result = g_fah->Move(uri, newDirUriTest2, testUri2);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
GTEST_LOG_(INFO) << "Move_0013 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest1);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1846,7 +1846,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Rename_0002, testing::ext
|
||||
Uri renameUri("");
|
||||
Uri sourceFileUri("");
|
||||
int result = g_fah->Rename(sourceFileUri, "testRename.txt", renameUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Rename_0002 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_Rename_0002 occurs an exception.";
|
||||
@ -1881,7 +1881,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Rename_0003, testing::ext
|
||||
Uri renameUri("");
|
||||
Uri sourceFileUri("storage/media/100/local/files/Download/test/test.txt");
|
||||
result = g_fah->Rename(sourceFileUri, "testRename.txt", renameUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Rename_0003 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1908,7 +1908,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Rename_0004, testing::ext
|
||||
Uri renameUri("");
|
||||
Uri sourceFileUri("~!@#$%^&*()_");
|
||||
int result = g_fah->Rename(sourceFileUri, "testRename.txt", renameUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Rename_0004 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_Rename_0004 occurs an exception.";
|
||||
@ -1942,7 +1942,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Rename_0005, testing::ext
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
Uri renameUri("");
|
||||
result = g_fah->Rename(testUri, "", renameUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Rename_0005 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -2038,7 +2038,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Rename_0007, testing::ext
|
||||
Uri testUri(str);
|
||||
Uri renameUri("");
|
||||
result = g_fah->Rename(testUri, "test.txt", renameUri);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
GTEST_LOG_(INFO) << "Rename_0007 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -2290,7 +2290,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_ListFile_0005, testing::e
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter;
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
}
|
||||
@ -2405,7 +2405,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_Access_0001, testing::ext
|
||||
Uri newDirUriTest(str + "/test.txt");
|
||||
bool isExist = false;
|
||||
result = g_fah->Access(newDirUriTest, isExist);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
EXPECT_FALSE(isExist);
|
||||
}
|
||||
} catch (...) {
|
||||
@ -2563,7 +2563,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_UriToFileInfo_0003, testi
|
||||
Uri parentUri(std::string("\?\?\?\?/") + info[i].uri);
|
||||
FileInfo fileinfo;
|
||||
result = g_fah->UriToFileInfo(parentUri, fileinfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_INVALID_URI);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_URIS);
|
||||
}
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_UriToFileInfo_0003 occurs an exception.";
|
||||
@ -2597,7 +2597,7 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_UriToFileInfo_0004, testi
|
||||
Uri parentUri(str);
|
||||
FileInfo fileinfo;
|
||||
result = g_fah->UriToFileInfo(parentUri, fileinfo);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
}
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_UriToFileInfo_0004 occurs an exception.";
|
||||
@ -2665,10 +2665,10 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_creator_0000, testing::ex
|
||||
GTEST_LOG_(INFO) << "FileExtensionHelperTest-begin external_file_access_creator_0000";
|
||||
try {
|
||||
setuid(UID_TRANSFORM_TMP);
|
||||
shared_ptr<FileAccessHelper> helper = FileAccessHelper::Creator(g_context);
|
||||
std::pair<shared_ptr<FileAccessHelper>, int> helper = FileAccessHelper::Creator(g_context);
|
||||
setuid(UID_DEFAULT);
|
||||
ASSERT_TRUE(helper != nullptr);
|
||||
bool succ = helper->Release();
|
||||
ASSERT_TRUE(helper.first != nullptr);
|
||||
bool succ = helper.first->Release();
|
||||
EXPECT_TRUE(succ);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_creator_0000 occurs an exception.";
|
||||
@ -2707,10 +2707,10 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_creator_0001, testing::ex
|
||||
}
|
||||
EXPECT_TRUE(sus);
|
||||
vector<AAFwk::Want> wants{want};
|
||||
shared_ptr<FileAccessHelper> helper = FileAccessHelper::Creator(g_context, wants);
|
||||
std::pair<shared_ptr<FileAccessHelper>, int> helper = FileAccessHelper::Creator(g_context, wants);
|
||||
setuid(UID_DEFAULT);
|
||||
ASSERT_TRUE(helper != nullptr);
|
||||
bool succ = helper->Release();
|
||||
ASSERT_TRUE(helper.first != nullptr);
|
||||
bool succ = helper.first->Release();
|
||||
EXPECT_TRUE(succ);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_creator_0001 occurs an exception.";
|
||||
@ -2733,8 +2733,8 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_creator_0002, testing::ex
|
||||
GTEST_LOG_(INFO) << "FileExtensionHelperTest-begin external_file_access_creator_0002";
|
||||
try {
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
shared_ptr<FileAccessHelper> helper = FileAccessHelper::Creator(context);
|
||||
ASSERT_TRUE(helper == nullptr);
|
||||
std::pair<shared_ptr<FileAccessHelper>, int> helper = FileAccessHelper::Creator(context);
|
||||
ASSERT_TRUE(helper.first == nullptr);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_creator_0002 occurs an exception.";
|
||||
}
|
||||
@ -2757,8 +2757,8 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_creator_0003, testing::ex
|
||||
try {
|
||||
std::vector<AAFwk::Want> wants;
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
shared_ptr<FileAccessHelper> helper = FileAccessHelper::Creator(context, wants);
|
||||
ASSERT_TRUE(helper == nullptr);
|
||||
std::pair<shared_ptr<FileAccessHelper>, int> helper = FileAccessHelper::Creator(context, wants);
|
||||
ASSERT_TRUE(helper.first == nullptr);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_creator_0003 occurs an exception.";
|
||||
}
|
||||
@ -2780,8 +2780,8 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_creator_0004, testing::ex
|
||||
GTEST_LOG_(INFO) << "FileExtensionHelperTest-begin external_file_access_creator_0004";
|
||||
try {
|
||||
std::vector<AAFwk::Want> wants;
|
||||
shared_ptr<FileAccessHelper> helper = FileAccessHelper::Creator(g_context, wants);
|
||||
ASSERT_TRUE(helper == nullptr);
|
||||
std::pair<shared_ptr<FileAccessHelper>, int> helper = FileAccessHelper::Creator(g_context, wants);
|
||||
ASSERT_TRUE(helper.first == nullptr);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_creator_0004 occurs an exception.";
|
||||
}
|
||||
@ -2805,8 +2805,8 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_creator_0005, testing::ex
|
||||
AAFwk::Want want;
|
||||
want.SetElementName("NotExistBundleName", "NotExistAbilityName");
|
||||
std::vector<AAFwk::Want> wants{want};
|
||||
shared_ptr<FileAccessHelper> helper = FileAccessHelper::Creator(g_context, wants);
|
||||
ASSERT_TRUE(helper == nullptr);
|
||||
std::pair<shared_ptr<FileAccessHelper>, int> helper = FileAccessHelper::Creator(g_context, wants);
|
||||
ASSERT_TRUE(helper.first == nullptr);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_creator_0005 occurs an exception.";
|
||||
}
|
||||
@ -2829,8 +2829,8 @@ HWTEST_F(FileExtensionHelperTest, external_file_access_creator_0006, testing::ex
|
||||
try {
|
||||
std::vector<AAFwk::Want> wants;
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
shared_ptr<FileAccessHelper> helper = FileAccessHelper::Creator(context, wants);
|
||||
ASSERT_TRUE(helper == nullptr);
|
||||
std::pair<shared_ptr<FileAccessHelper>, int> helper = FileAccessHelper::Creator(context, wants);
|
||||
ASSERT_TRUE(helper.first == nullptr);
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "external_file_access_creator_0006 occurs an exception.";
|
||||
}
|
||||
|
@ -133,10 +133,10 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_OpenFile_0000, testing::
|
||||
Uri parentUri = GetParentUri();
|
||||
bool isExist = false;
|
||||
int result = g_fah->Access(g_newDirUri, isExist);
|
||||
EXPECT_LE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
if (!isExist) {
|
||||
result = g_fah->Mkdir(parentUri, "Download", g_newDirUri);
|
||||
EXPECT_LE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
}
|
||||
Uri newDirUriTest("datashare:///media/root/file");
|
||||
FileInfo fileInfo;
|
||||
@ -188,7 +188,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_OpenFile_0001, testing::
|
||||
Uri uri("");
|
||||
int fd;
|
||||
int result = g_fah->OpenFile(uri, WRITE_READ, fd);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0001 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "medialibrary_file_access_OpenFile_0001 occurs an exception.";
|
||||
@ -212,7 +212,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_OpenFile_0002, testing::
|
||||
Uri uri("storage/media/100/local/files/Download/medialibrary_file_access_OpenFile_0002.txt");
|
||||
int fd;
|
||||
int result = g_fah->OpenFile(uri, WRITE_READ, fd);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0002 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "medialibrary_file_access_OpenFile_0002 occurs an exception.";
|
||||
@ -236,7 +236,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_OpenFile_0003, testing::
|
||||
Uri uri("~!@#$%^&*()_");
|
||||
int fd;
|
||||
int result = g_fah->OpenFile(uri, WRITE_READ, fd);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0003 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "medialibrary_file_access_OpenFile_0003 occurs an exception.";
|
||||
@ -263,7 +263,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_OpenFile_0004, testing::
|
||||
int fd;
|
||||
int flag = -1;
|
||||
result = g_fah->OpenFile(newFileUri, flag, fd);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "OpenFile_0004 result:" << result;
|
||||
result = g_fah->Delete(newFileUri);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -532,7 +532,7 @@ static void CreateFileTdd(shared_ptr<FileAccessHelper> fahs, Uri parent, std::st
|
||||
{
|
||||
GTEST_LOG_(INFO) << "FileAccessHelperTest-begin medialibrary_file_access_CreateFileTdd";
|
||||
int ret = fahs->CreateFile(parent, displayName, newDir);
|
||||
if (ret < OHOS::FileAccessFwk::ERR_OK) {
|
||||
if (ret != OHOS::FileAccessFwk::ERR_OK) {
|
||||
GTEST_LOG_(ERROR) << "CreateFileTdd get result error, code:" << ret;
|
||||
return;
|
||||
}
|
||||
@ -705,7 +705,7 @@ static void MkdirTdd(shared_ptr<FileAccessHelper> fahs, Uri parent, std::string
|
||||
{
|
||||
GTEST_LOG_(INFO) << "FileAccessHelperTest-begin medialibrary_file_access_MkdirTdd";
|
||||
int ret = fahs->Mkdir(parent, displayName, newDir);
|
||||
if (ret < OHOS::FileAccessFwk::ERR_OK) {
|
||||
if (ret != OHOS::FileAccessFwk::ERR_OK) {
|
||||
GTEST_LOG_(ERROR) << "MkdirTdd get result error, code:" << ret;
|
||||
return;
|
||||
}
|
||||
@ -822,7 +822,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Delete_0002, testing::ex
|
||||
try {
|
||||
Uri selectFileUri("");
|
||||
int result = g_fah->Delete(selectFileUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Delete_0002 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "medialibrary_file_access_Delete_0002 occurs an exception.";
|
||||
@ -848,7 +848,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Delete_0003, testing::ex
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
Uri selectFileUri("storage/media/100/local/files/Download/test");
|
||||
result = g_fah->Delete(selectFileUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Delete_0003 result:" << result;
|
||||
@ -873,7 +873,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Delete_0004, testing::ex
|
||||
try {
|
||||
Uri selectFileUri("!@#$%^&*()");
|
||||
int result = g_fah->Delete(selectFileUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Delete_0004 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "medialibrary_file_access_Delete_0004 occurs an exception.";
|
||||
@ -1023,7 +1023,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Move_0002, testing::ext:
|
||||
Uri testUri("");
|
||||
Uri sourceFileUri("");
|
||||
result = g_fah->Move(sourceFileUri, newDirUriTest, testUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0002 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1058,7 +1058,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Move_0003, testing::ext:
|
||||
Uri testUri2("");
|
||||
Uri sourceFileUri("storage/media/100/local/files/Download/test1/test.txt");
|
||||
result = g_fah->Move(sourceFileUri, newDirUriTest2, testUri2);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0003 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest1);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1089,7 +1089,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Move_0004, testing::ext:
|
||||
Uri testUri("");
|
||||
Uri sourceFileUri("~!@#$%^&*()_");
|
||||
result = g_fah->Move(sourceFileUri, newDirUriTest, testUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0004 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1121,7 +1121,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Move_0005, testing::ext:
|
||||
Uri testUri2("");
|
||||
Uri targetParentUri("");
|
||||
result = g_fah->Move(testUri, targetParentUri, testUri2);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0005 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1156,7 +1156,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Move_0006, testing::ext:
|
||||
Uri testUri2("");
|
||||
Uri targetParentUri("storage/media/100/local/files/Download/test2");
|
||||
result = g_fah->Move(testUri, targetParentUri, testUri2);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0006 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest1);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1193,7 +1193,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Move_0007, testing::ext:
|
||||
Uri testUri2("");
|
||||
Uri targetParentUri("~!@#$^%&*()_");
|
||||
result = g_fah->Move(testUri, targetParentUri, testUri2);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Move_0007 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest1);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1447,7 +1447,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Rename_0002, testing::ex
|
||||
Uri renameUri("");
|
||||
Uri sourceFileUri("");
|
||||
int result = g_fah->Rename(sourceFileUri, "testRename.txt", renameUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Rename_0002 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "medialibrary_file_access_Rename_0002 occurs an exception.";
|
||||
@ -1477,7 +1477,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Rename_0003, testing::ex
|
||||
Uri renameUri("");
|
||||
Uri sourceFileUri("storage/media/100/local/files/Download/test/test.txt");
|
||||
result = g_fah->Rename(sourceFileUri, "testRename.txt", renameUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Rename_0003 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1503,7 +1503,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Rename_0004, testing::ex
|
||||
Uri renameUri("");
|
||||
Uri sourceFileUri("~!@#$%^&*()_");
|
||||
int result = g_fah->Rename(sourceFileUri, "testRename.txt", renameUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Rename_0004 result:" << result;
|
||||
} catch (...) {
|
||||
GTEST_LOG_(ERROR) << "medialibrary_file_access_Rename_0004 occurs an exception.";
|
||||
@ -1532,7 +1532,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_Rename_0005, testing::ex
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
Uri renameUri("");
|
||||
result = g_fah->Rename(testUri, "", renameUri);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "Rename_0005 result:" << result;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
EXPECT_GE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
@ -1649,7 +1649,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0001, testing::
|
||||
vector<FileAccessFwk::FileInfo> fileInfoVec;
|
||||
FileFilter filter({}, {}, {}, 0, 0, false, false);
|
||||
int result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "ListFile_0001 result:" << fileInfoVec.size() << endl;
|
||||
} catch (...) {
|
||||
@ -1685,7 +1685,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ListFile_0002, testing::
|
||||
vector<FileAccessFwk::FileInfo> fileInfoVec;
|
||||
FileFilter filter({}, {}, {}, 0, 0, false, false);
|
||||
result = g_fah->ListFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
EXPECT_LT(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_NE(result, OHOS::FileAccessFwk::ERR_OK);
|
||||
EXPECT_EQ(fileInfoVec.size(), OHOS::FileAccessFwk::ERR_OK);
|
||||
GTEST_LOG_(INFO) << "ListFile_0002 result:" << fileInfoVec.size() << endl;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
@ -2094,7 +2094,7 @@ HWTEST_F(FileAccessHelperTest, medialibrary_file_access_ScanFile_0005, testing::
|
||||
std::vector<FileInfo> fileInfoVec;
|
||||
FileFilter filter({".q1w2e3r4"}, {}, {}, 0, 0, false, true);
|
||||
result = g_fah->ScanFile(fileInfo, offset, maxCount, filter, fileInfoVec);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::ERR_IPC_ERROR);
|
||||
EXPECT_EQ(result, OHOS::FileAccessFwk::E_IPCS);
|
||||
EXPECT_EQ(fileInfoVec.size(), 0);
|
||||
GTEST_LOG_(INFO) << "ScanFile_0005 result:" << fileInfoVec.size() << endl;
|
||||
result = g_fah->Delete(newDirUriTest);
|
||||
|
@ -43,13 +43,13 @@ bool NapiFileInfoExporter::Export()
|
||||
std::tie(succ, classValue) = NClass::DefineClass(exports_.env_, className,
|
||||
NapiFileInfoExporter::Constructor, std::move(props));
|
||||
if (!succ) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(exports_.env_, "INNER BUG. Failed to define class NapiFileInfoExporter");
|
||||
NError(E_GETRESULT).ThrowErr(exports_.env_);
|
||||
return false;
|
||||
}
|
||||
|
||||
succ = NClass::SaveClass(exports_.env_, className, classValue);
|
||||
if (!succ) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(exports_.env_, "INNER BUG. Failed to save class NapiFileInfoExporter");
|
||||
NError(E_GETRESULT).ThrowErr(exports_.env_);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -60,18 +60,18 @@ napi_value NapiFileInfoExporter::Constructor(napi_env env, napi_callback_info in
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileInfoEntity = std::make_unique<FileInfoEntity>();
|
||||
if (fileInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of fileInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!NClass::SetEntityFor<FileInfoEntity>(env, funcArg.GetThisVar(), std::move(fileInfoEntity))) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "INNER BUG. Failed to wrap entity for obj FileInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ napi_value NapiFileInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -90,14 +90,14 @@ napi_value NapiFileInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
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, "ListFile get FileFilter param fail");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto fileInfoEntity = NClass::GetEntityOf<FileInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (fileInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of FileInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -107,19 +107,19 @@ napi_value NapiFileInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
if (fileInfoEntity->fileAccessHelper == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "fileAccessHelper is null.");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto objFileIteratorExporter = NClass::InstantiateClass(env, NapiFileIteratorExporter::className_, {});
|
||||
if (objFileIteratorExporter == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot instantiate class NapiFileIteratorExporter");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileIteratorEntity = NClass::GetEntityOf<FileIteratorEntity>(env, objFileIteratorExporter);
|
||||
if (fileIteratorEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get the entity of FileIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ napi_value NapiFileInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
auto ret = fileInfoEntity->fileAccessHelper->ListFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset,
|
||||
MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
NError(ret).ThrowErr(env, "exec ListFile fail");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ napi_value NapiFileInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -155,14 +155,14 @@ napi_value NapiFileInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
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, "ScanFile get FileFilter param fail");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto fileInfoEntity = NClass::GetEntityOf<FileInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (fileInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of FileInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -172,19 +172,19 @@ napi_value NapiFileInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
if (fileInfoEntity->fileAccessHelper == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "fileAccessHelper is null.");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto objFileIteratorExporter = NClass::InstantiateClass(env, NapiFileIteratorExporter::className_, {});
|
||||
if (objFileIteratorExporter == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot instantiate class NapiFileIteratorExporter");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileIteratorEntity = NClass::GetEntityOf<FileIteratorEntity>(env, objFileIteratorExporter);
|
||||
if (fileIteratorEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get the entity of FileIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ napi_value NapiFileInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
auto ret = fileInfoEntity->fileAccessHelper->ScanFile(fileInfoEntity->fileInfo, fileIteratorEntity->offset,
|
||||
MAX_COUNT, fileIteratorEntity->filter, fileIteratorEntity->fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
NError(ret).ThrowErr(env, "exec ScanFile fail");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -212,13 +212,13 @@ static FileInfoEntity *GetFileInfoEntity(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileInfoEntity = NClass::GetEntityOf<FileInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (fileInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of FileInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -37,13 +37,13 @@ bool NapiFileIteratorExporter::Export()
|
||||
std::tie(succ, classValue) = NClass::DefineClass(exports_.env_, className,
|
||||
NapiFileIteratorExporter::Constructor, std::move(props));
|
||||
if (!succ) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(exports_.env_, "INNER BUG. Failed to define class NapiFileIteratorExporter");
|
||||
NError(E_GETRESULT).ThrowErr(exports_.env_);
|
||||
return false;
|
||||
}
|
||||
|
||||
succ = NClass::SaveClass(exports_.env_, className, classValue);
|
||||
if (!succ) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(exports_.env_, "INNER BUG. Failed to save class NapiFileIteratorExporter");
|
||||
NError(E_GETRESULT).ThrowErr(exports_.env_);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -54,18 +54,18 @@ napi_value NapiFileIteratorExporter::Constructor(napi_env env, napi_callback_inf
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileIteratorEntity = std::make_unique<FileIteratorEntity>();
|
||||
if (fileIteratorEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "New obj FileIteratorEntity fail");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!NClass::SetEntityFor<FileIteratorEntity>(env, funcArg.GetThisVar(), std::move(fileIteratorEntity))) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "INNER BUG. Failed to wrap entity for obj FileIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -131,13 +131,13 @@ napi_value NapiFileIteratorExporter::Next(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileIteratorEntity = NClass::GetEntityOf<FileIteratorEntity>(env, funcArg.GetThisVar());
|
||||
if (fileIteratorEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of FileIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -148,25 +148,25 @@ napi_value NapiFileIteratorExporter::Next(napi_env env, napi_callback_info info)
|
||||
|
||||
auto objFileInfoExporter = NClass::InstantiateClass(env, NapiFileInfoExporter::className_, {});
|
||||
if (objFileInfoExporter == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot instantiate class NapiFileInfoExporter");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileInfoEntity = NClass::GetEntityOf<FileInfoEntity>(env, objFileInfoExporter);
|
||||
if (fileInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get the entity of FileInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (fileIteratorEntity->fileAccessHelper == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "fileAccessHelper is null.");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto retNVal = NVal::CreateObject(env);
|
||||
int ret = MakeResult(objFileInfoExporter, fileIteratorEntity, fileInfoEntity, env, retNVal);
|
||||
if (ret != ERR_OK) {
|
||||
NError(ret).ThrowErr(env, "MakeResult fail.");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "napi_fileaccess_helper.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "file_access_framework_errno.h"
|
||||
@ -26,7 +27,6 @@
|
||||
#include "ifile_access_notify.h"
|
||||
#include "napi_base_context.h"
|
||||
#include "napi_common_fileaccess.h"
|
||||
#include "napi_error.h"
|
||||
#include "napi_file_info_exporter.h"
|
||||
#include "napi_notify_callback.h"
|
||||
#include "napi_root_iterator_exporter.h"
|
||||
@ -52,42 +52,45 @@ static napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info i
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value thisVar = funcArg.GetThisVar();
|
||||
std::shared_ptr<FileAccessHelper> fileAccessHelper = nullptr;
|
||||
std::pair<std::shared_ptr<FileAccessHelper>, int> createResult{nullptr, ERR_OK};
|
||||
bool isStageMode = false;
|
||||
napi_status status = AbilityRuntime::IsStageContext(env, funcArg.GetArg(PARAM0), isStageMode);
|
||||
if (status != napi_ok || !isStageMode) {
|
||||
HILOG_INFO("No support FA Model");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = OHOS::AbilityRuntime::GetStageModeContext(env, funcArg.GetArg(PARAM0));
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("FileAccessHelperConstructor: failed to get native context");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (funcArg.GetArgc() == NARG_CNT::ONE) {
|
||||
fileAccessHelper = FileAccessHelper::Creator(context);
|
||||
createResult = FileAccessHelper::Creator(context);
|
||||
} else if (funcArg.GetArgc() == NARG_CNT::TWO) {
|
||||
std::vector<AAFwk::Want> wants;
|
||||
bool suss = UnwrapArrayWantFromJS(env, funcArg.GetArg(PARAM1), wants);
|
||||
if (!suss) {
|
||||
HILOG_ERROR("UnwrapArrayWantFromJS failed to get native wants");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
fileAccessHelper = FileAccessHelper::Creator(context, wants);
|
||||
createResult = FileAccessHelper::Creator(context, wants);
|
||||
}
|
||||
|
||||
if (fileAccessHelper == nullptr) {
|
||||
HILOG_ERROR("FileAccessHelperConstructor: fileAccessHelper is nullptr");
|
||||
if (createResult.first == nullptr || createResult.second != ERR_OK) {
|
||||
HILOG_ERROR("FileAccessHelperConstructor: Creator failed ret=%{public}d", createResult.second);
|
||||
NError(createResult.second).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
g_fileAccessHelperList.emplace_back(fileAccessHelper);
|
||||
g_fileAccessHelperList.emplace_back(createResult.first);
|
||||
|
||||
auto finalize = [](napi_env env, void *data, void *hint) {
|
||||
FileAccessHelper *objectInfo = static_cast<FileAccessHelper *>(data);
|
||||
@ -99,8 +102,9 @@ static napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info i
|
||||
objectInfo = nullptr;
|
||||
}
|
||||
};
|
||||
if (napi_wrap(env, thisVar, fileAccessHelper.get(), finalize, nullptr, nullptr) != napi_ok) {
|
||||
finalize(env, fileAccessHelper.get(), nullptr);
|
||||
if (napi_wrap(env, thisVar, createResult.first.get(), finalize, nullptr, nullptr) != napi_ok) {
|
||||
finalize(env, createResult.first.get(), nullptr);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return thisVar;
|
||||
@ -110,7 +114,7 @@ napi_value AcquireFileAccessHelperWrap(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -182,13 +186,13 @@ napi_value NAPI_GetFileAccessAbilityInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto result = std::make_shared<std::vector<AAFwk::Want>>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -210,7 +214,7 @@ napi_value NAPI_GetFileAccessAbilityInfo(napi_env env, napi_callback_info info)
|
||||
}
|
||||
NVal cb(env, funcArg[NARG_POS::FIRST]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -271,18 +275,18 @@ void InitOpenFlags(napi_env env, napi_value exports)
|
||||
static FileAccessHelper *GetFileAccessHelper(napi_env env, napi_value thisVar)
|
||||
{
|
||||
if (thisVar == nullptr) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FileAccessHelper *fileAccessHelper = nullptr;
|
||||
if (napi_unwrap(env, thisVar, (void **)&fileAccessHelper) != napi_ok) {
|
||||
NapiError(ERR_GET_FILEACCESS_HELPER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (fileAccessHelper == nullptr) {
|
||||
NapiError(ERR_GET_FILEACCESS_HELPER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return fileAccessHelper;
|
||||
@ -297,13 +301,13 @@ static std::tuple<bool, std::unique_ptr<char[]>, std::unique_ptr<char[]>> GetRea
|
||||
std::unique_ptr<char[]> name = nullptr;
|
||||
std::tie(succ, uri, std::ignore) = NVal(env, sourceFile).ToUTF8String();
|
||||
if (!succ) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return { false, std::move(uri), std::move(name) };
|
||||
}
|
||||
|
||||
std::tie(succ, name, std::ignore) = NVal(env, targetParent).ToUTF8String();
|
||||
if (!succ) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return { false, std::move(uri), std::move(name) };
|
||||
}
|
||||
|
||||
@ -314,7 +318,7 @@ napi_value NAPI_OpenFile(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -322,14 +326,14 @@ napi_value NAPI_OpenFile(napi_env env, napi_callback_info info)
|
||||
std::unique_ptr<char[]> uri;
|
||||
std::tie(succ, uri, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
|
||||
if (!succ) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int flags;
|
||||
std::tie(succ, flags) = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32();
|
||||
if (!succ) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -340,7 +344,7 @@ napi_value NAPI_OpenFile(napi_env env, napi_callback_info info)
|
||||
|
||||
auto result = std::make_shared<int>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -365,7 +369,7 @@ napi_value NAPI_OpenFile(napi_env env, napi_callback_info info)
|
||||
|
||||
NVal cb(env, funcArg[NARG_POS::THIRD]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -375,7 +379,7 @@ napi_value NAPI_CreateFile(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -394,7 +398,7 @@ napi_value NAPI_CreateFile(napi_env env, napi_callback_info info)
|
||||
|
||||
auto result = std::make_shared<string>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -422,7 +426,7 @@ napi_value NAPI_CreateFile(napi_env env, napi_callback_info info)
|
||||
|
||||
NVal cb(env, funcArg[NARG_POS::THIRD]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -432,7 +436,7 @@ napi_value NAPI_Mkdir(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -451,7 +455,7 @@ napi_value NAPI_Mkdir(napi_env env, napi_callback_info info)
|
||||
|
||||
auto result = std::make_shared<string>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -479,7 +483,7 @@ napi_value NAPI_Mkdir(napi_env env, napi_callback_info info)
|
||||
|
||||
NVal cb(env, funcArg[NARG_POS::THIRD]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -489,7 +493,7 @@ napi_value NAPI_Delete(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -497,7 +501,7 @@ napi_value NAPI_Delete(napi_env env, napi_callback_info info)
|
||||
std::unique_ptr<char[]> uri;
|
||||
std::tie(succ, uri, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
|
||||
if (!succ) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -508,7 +512,7 @@ napi_value NAPI_Delete(napi_env env, napi_callback_info info)
|
||||
|
||||
auto result = std::make_shared<int>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -516,13 +520,13 @@ napi_value NAPI_Delete(napi_env env, napi_callback_info info)
|
||||
auto cbExec = [uriString, result, fileAccessHelper]() -> NError {
|
||||
OHOS::Uri uri(uriString);
|
||||
*result = fileAccessHelper->Delete(uri);
|
||||
return NError(ERRNO_NOERR);
|
||||
return NError(*result);
|
||||
};
|
||||
auto cbComplete = [result](napi_env env, NError err) -> NVal {
|
||||
if (err) {
|
||||
return { env, err.GetNapiErr(env) };
|
||||
}
|
||||
return { NVal::CreateInt32(env, *result) };
|
||||
return { NVal::CreateInt32(env, ERRNO_NOERR) };
|
||||
};
|
||||
|
||||
const std::string procedureName = "delete";
|
||||
@ -533,7 +537,7 @@ napi_value NAPI_Delete(napi_env env, napi_callback_info info)
|
||||
|
||||
NVal cb(env, funcArg[NARG_POS::SECOND]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -543,7 +547,7 @@ napi_value NAPI_Move(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -562,7 +566,7 @@ napi_value NAPI_Move(napi_env env, napi_callback_info info)
|
||||
|
||||
auto result = std::make_shared<string>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -591,7 +595,7 @@ napi_value NAPI_Move(napi_env env, napi_callback_info info)
|
||||
|
||||
NVal cb(env, funcArg[NARG_POS::THIRD]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -601,7 +605,7 @@ napi_value NAPI_Rename(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -620,7 +624,7 @@ napi_value NAPI_Rename(napi_env env, napi_callback_info info)
|
||||
|
||||
auto result = std::make_shared<string>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -648,7 +652,7 @@ napi_value NAPI_Rename(napi_env env, napi_callback_info info)
|
||||
|
||||
NVal cb(env, funcArg[NARG_POS::THIRD]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -659,13 +663,13 @@ static int MakeGetRootsResult(napi_env &env, FileAccessHelper *helper, std::vect
|
||||
auto objRootIterator = NClass::InstantiateClass(env, NapiRootIteratorExporter::className_, {});
|
||||
if (objRootIterator == nullptr) {
|
||||
HILOG_INFO("Cannot instantiate class NapiRootIteratorExporter");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto rootIteratorEntity = NClass::GetEntityOf<RootIteratorEntity>(env, objRootIterator);
|
||||
if (rootIteratorEntity == nullptr) {
|
||||
HILOG_INFO("Cannot get the entity of RootIteratorEntity");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(rootIteratorEntity->entityOperateMutex);
|
||||
@ -681,19 +685,19 @@ napi_value NAPI_GetRoots(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FileAccessHelper *fileAccessHelper = GetFileAccessHelper(env, funcArg.GetThisVar());
|
||||
if (fileAccessHelper == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto result = std::make_shared<std::vector<RootInfo>>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -725,7 +729,7 @@ napi_value NAPI_GetRoots(napi_env env, napi_callback_info info)
|
||||
|
||||
NVal cb(env, funcArg[NARG_POS::FIRST]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -735,7 +739,7 @@ napi_value NAPI_Access(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -743,7 +747,7 @@ napi_value NAPI_Access(napi_env env, napi_callback_info info)
|
||||
std::unique_ptr<char[]> uri;
|
||||
std::tie(succ, uri, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
|
||||
if (!succ) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -775,7 +779,7 @@ napi_value NAPI_Access(napi_env env, napi_callback_info info)
|
||||
}
|
||||
NVal cb(env, funcArg[NARG_POS::SECOND]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
@ -786,13 +790,13 @@ static int MakeFileInfoResult(napi_env &env, FileAccessHelper *helper, FileInfo
|
||||
auto objFileInfo = NClass::InstantiateClass(env, NapiFileInfoExporter::className_, {});
|
||||
if (objFileInfo == nullptr) {
|
||||
HILOG_INFO("Cannot instantiate class NapiFileInfoExporter");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
|
||||
auto fileInfoEntity = NClass::GetEntityOf<FileInfoEntity>(env, objFileInfo);
|
||||
if (fileInfoEntity == nullptr) {
|
||||
HILOG_INFO("Cannot get the entity of fileInfoEntity");
|
||||
return ERR_NULL_POINTER;
|
||||
return E_GETRESULT;
|
||||
}
|
||||
fileInfoEntity->fileAccessHelper = helper;
|
||||
fileInfoEntity->fileInfo = std::move(fileinfo);
|
||||
@ -805,7 +809,7 @@ napi_value NAPI_UriToFileInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
|
||||
NapiError(ERR_PARAM_NUMBER).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -813,7 +817,7 @@ napi_value NAPI_UriToFileInfo(napi_env env, napi_callback_info info)
|
||||
std::unique_ptr<char[]> uri;
|
||||
std::tie(succ, uri, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
|
||||
if (!succ) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -824,7 +828,7 @@ napi_value NAPI_UriToFileInfo(napi_env env, napi_callback_info info)
|
||||
|
||||
auto result = std::make_shared<FileInfo>();
|
||||
if (result == nullptr) {
|
||||
NapiError(ERR_NULL_POINTER).ThrowErr(env);
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -857,7 +861,7 @@ napi_value NAPI_UriToFileInfo(napi_env env, napi_callback_info info)
|
||||
}
|
||||
NVal cb(env, funcArg[NARG_POS::SECOND]);
|
||||
if (!cb.TypeIs(napi_function)) {
|
||||
NapiError(ERR_INVALID_PARAM).ThrowErr(env);
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
||||
|
@ -44,13 +44,13 @@ int NapiNotifyCallback::OnNotify(const NotifyMessage& message)
|
||||
uv_work_t* work = new uv_work_t();
|
||||
if (work == nullptr) {
|
||||
HILOG_ERROR("failed to new uv_work_t");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
CallbackParam* param = new CallbackParam(this, message);
|
||||
if (param == nullptr) {
|
||||
HILOG_ERROR("failed to new param");
|
||||
delete work;
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
work->data = param;
|
||||
int ret = uv_queue_work(loop_, work,
|
||||
@ -85,7 +85,7 @@ int NapiNotifyCallback::OnNotify(const NotifyMessage& message)
|
||||
work->data = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
return ERR_NOTIFY_FAIL;
|
||||
return E_NOTIFY;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
|
@ -30,12 +30,12 @@ int IsDirectory(const int64_t mode)
|
||||
{
|
||||
if ((static_cast<uint32_t>(mode) & DOCUMENT_FLAG_REPRESENTS_DIR) != DOCUMENT_FLAG_REPRESENTS_DIR) {
|
||||
HILOG_ERROR("current FileInfo is not dir");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if ((static_cast<uint32_t>(mode) & DOCUMENT_FLAG_REPRESENTS_FILE) == DOCUMENT_FLAG_REPRESENTS_FILE) {
|
||||
HILOG_ERROR("file mode(%{public}" PRId64 ") is incorrect", mode);
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
@ -68,15 +68,15 @@ int GetFileFilterParam(const NVal &argv, FileFilter &filter)
|
||||
std::tie(ret, suffixs, std::ignore) = argv.GetProp("suffix").ToStringArray();
|
||||
if (!ret) {
|
||||
HILOG_ERROR("FileFilter get suffix param fail.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
if (!CheckSuffix(suffixs)) {
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
filter.SetSuffix(suffixs);
|
||||
filter.SetHasFilter(true);
|
||||
} else {
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (argv.HasProp("displayName")) {
|
||||
@ -84,7 +84,7 @@ int GetFileFilterParam(const NVal &argv, FileFilter &filter)
|
||||
std::tie(ret, displayNames, std::ignore) = argv.GetProp("displayName").ToStringArray();
|
||||
if (!ret) {
|
||||
HILOG_ERROR("FileFilter get displayName param fail.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
filter.SetDisplayName(displayNames);
|
||||
@ -96,7 +96,7 @@ int GetFileFilterParam(const NVal &argv, FileFilter &filter)
|
||||
std::tie(ret, mimeTypes, std::ignore) = argv.GetProp("mimeType").ToStringArray();
|
||||
if (!ret) {
|
||||
HILOG_ERROR("FileFilter get mimeType param fail.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
filter.SetMimeType(mimeTypes);
|
||||
@ -108,7 +108,7 @@ int GetFileFilterParam(const NVal &argv, FileFilter &filter)
|
||||
std::tie(ret, fileSizeOver) = argv.GetProp("fileSizeOver").ToInt64();
|
||||
if (!ret) {
|
||||
HILOG_ERROR("FileFilter get fileSizeOver param fail.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
filter.SetFileSizeOver(fileSizeOver);
|
||||
@ -120,7 +120,7 @@ int GetFileFilterParam(const NVal &argv, FileFilter &filter)
|
||||
std::tie(ret, lastModifiedAfter) = argv.GetProp("lastModifiedAfter").ToDouble();
|
||||
if (!ret) {
|
||||
HILOG_ERROR("FileFilter get lastModifiedAfter param fail.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
filter.SetLastModifiedAfter(lastModifiedAfter);
|
||||
@ -132,7 +132,7 @@ int GetFileFilterParam(const NVal &argv, FileFilter &filter)
|
||||
std::tie(ret, excludeMedia) = argv.GetProp("excludeMedia").ToBool();
|
||||
if (!ret) {
|
||||
HILOG_ERROR("FileFilter get excludeMedia param fail.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
filter.SetExcludeMedia(excludeMedia);
|
||||
@ -141,7 +141,7 @@ int GetFileFilterParam(const NVal &argv, FileFilter &filter)
|
||||
|
||||
if (!filter.GetHasFilter()) {
|
||||
HILOG_ERROR("FileFilter must have one property.");
|
||||
return ERR_INVALID_PARAM;
|
||||
return EINVAL;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
@ -45,13 +45,13 @@ bool NapiRootInfoExporter::Export()
|
||||
std::tie(succ, classValue) = NClass::DefineClass(exports_.env_, className,
|
||||
NapiRootInfoExporter::Constructor, std::move(props));
|
||||
if (!succ) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(exports_.env_, "INNER BUG. Failed to define class NapiRootInfoExporter");
|
||||
NError(E_GETRESULT).ThrowErr(exports_.env_);
|
||||
return false;
|
||||
}
|
||||
|
||||
succ = NClass::SaveClass(exports_.env_, className, classValue);
|
||||
if (!succ) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(exports_.env_, "INNER BUG. Failed to save class NapiRootInfoExporter");
|
||||
NError(E_GETRESULT).ThrowErr(exports_.env_);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -62,18 +62,18 @@ napi_value NapiRootInfoExporter::Constructor(napi_env env, napi_callback_info in
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rootInfoEntity = std::make_unique<RootInfoEntity>();
|
||||
if (rootInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of RootInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!NClass::SetEntityFor<RootInfoEntity>(env, funcArg.GetThisVar(), std::move(rootInfoEntity))) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "INNER BUG. Failed to wrap entity for obj RootInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ napi_value NapiRootInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -92,31 +92,31 @@ napi_value NapiRootInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
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, "ListFile get FileFilter param fail");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto rootEntity = NClass::GetEntityOf<RootInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (rootEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of FileInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (rootEntity->fileAccessHelper == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "fileAccessHelper is null.");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value objFileIteratorExporter = NClass::InstantiateClass(env, NapiFileIteratorExporter::className_, {});
|
||||
if (objFileIteratorExporter == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot instantiate class NapiFileIteratorExporter");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileIteratorEntity = NClass::GetEntityOf<FileIteratorEntity>(env, objFileIteratorExporter);
|
||||
if (fileIteratorEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get the entity of FileIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ napi_value NapiRootInfoExporter::ListFile(napi_env env, napi_callback_info info)
|
||||
auto ret = rootEntity->fileAccessHelper->ListFile(fileInfo, fileIteratorEntity->offset,
|
||||
MAX_COUNT, filter, fileIteratorEntity->fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
NError(ret).ThrowErr(env, "ListFile get result fail.");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ napi_value NapiRootInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -155,31 +155,31 @@ napi_value NapiRootInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
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, "ScanFile get FileFilter param fail");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto rootEntity = NClass::GetEntityOf<RootInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (rootEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of FileInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (rootEntity->fileAccessHelper == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "fileAccessHelper is null.");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value objFileIteratorExporter = NClass::InstantiateClass(env, NapiFileIteratorExporter::className_, {});
|
||||
if (objFileIteratorExporter == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot instantiate class NapiFileIteratorExporter");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto fileIteratorEntity = NClass::GetEntityOf<FileIteratorEntity>(env, objFileIteratorExporter);
|
||||
if (fileIteratorEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get the entity of FileIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ napi_value NapiRootInfoExporter::ScanFile(napi_env env, napi_callback_info info)
|
||||
auto ret = rootEntity->fileAccessHelper->ScanFile(fileInfo, fileIteratorEntity->offset,
|
||||
MAX_COUNT, filter, fileIteratorEntity->fileInfoVec);
|
||||
if (ret != ERR_OK) {
|
||||
NError(ret).ThrowErr(env, "ScanFile get result fail.");
|
||||
NError(ret).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -210,13 +210,13 @@ napi_value NapiRootInfoExporter::GetDeviceType(napi_env env, napi_callback_info
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rootInfoEntity = NClass::GetEntityOf<RootInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (rootInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of RootInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -227,13 +227,13 @@ napi_value NapiRootInfoExporter::GetUri(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rootInfoEntity = NClass::GetEntityOf<RootInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (rootInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of RootInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -244,13 +244,13 @@ napi_value NapiRootInfoExporter::GetDisplayName(napi_env env, napi_callback_info
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rootInfoEntity = NClass::GetEntityOf<RootInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (rootInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of RootInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -261,13 +261,13 @@ napi_value NapiRootInfoExporter::GetDeviceFlags(napi_env env, napi_callback_info
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rootInfoEntity = NClass::GetEntityOf<RootInfoEntity>(env, funcArg.GetThisVar());
|
||||
if (rootInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of RootInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -34,14 +34,13 @@ bool NapiRootIteratorExporter::Export()
|
||||
std::tie(succ, classValue) = NClass::DefineClass(exports_.env_, className,
|
||||
NapiRootIteratorExporter::Constructor, std::move(props));
|
||||
if (!succ) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(exports_.env_,
|
||||
"INNER BUG. Failed to define class NapiRootIteratorExporter");
|
||||
NError(E_GETRESULT).ThrowErr(exports_.env_);
|
||||
return false;
|
||||
}
|
||||
|
||||
succ = NClass::SaveClass(exports_.env_, className, classValue);
|
||||
if (!succ) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(exports_.env_, "INNER BUG. Failed to save class NapiRootIteratorExporter");
|
||||
NError(E_GETRESULT).ThrowErr(exports_.env_);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -52,18 +51,18 @@ napi_value NapiRootIteratorExporter::Constructor(napi_env env, napi_callback_inf
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rootIteratorEntity = std::make_unique<RootIteratorEntity>();
|
||||
if (rootIteratorEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of rootIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!NClass::SetEntityFor<RootIteratorEntity>(env, funcArg.GetThisVar(), std::move(rootIteratorEntity))) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "INNER BUG. Failed to wrap entity for obj FileIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -74,26 +73,26 @@ napi_value NapiRootIteratorExporter::Next(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NFuncArg funcArg(env, info);
|
||||
if (!funcArg.InitArgs(NARG_CNT::ZERO)) {
|
||||
NError(ERR_PARAM_NUMBER).ThrowErr(env, "Number of arguments unmatched");
|
||||
NError(EINVAL).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value thisVar = funcArg.GetThisVar();
|
||||
auto rootIterator = NClass::GetEntityOf<RootIteratorEntity>(env, thisVar);
|
||||
if (rootIterator == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get entity of RootIteratorEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value objRootInfoExporter = NClass::InstantiateClass(env, NapiRootInfoExporter::className_, {});
|
||||
if (objRootInfoExporter == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot instantiate class NapiRootInfoExporter");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rootInfoEntity = NClass::GetEntityOf<RootInfoEntity>(env, objRootInfoExporter);
|
||||
if (rootInfoEntity == nullptr) {
|
||||
NError(ERR_NULL_POINTER).ThrowErr(env, "Cannot get the entity of RootInfoEntity");
|
||||
NError(E_GETRESULT).ThrowErr(env);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,12 @@ const DEFAULT_MODE = 0o666;
|
||||
const CREATE_FILE_FLAGS = 0o100;
|
||||
const URI_SCHEME = 'datashare://';
|
||||
const DOMAIN_CODE = 0x0001;
|
||||
const TAG = 'js_server';
|
||||
const TAG = 'ExternalFileManager';
|
||||
const ERR_OK = 0;
|
||||
const ERR_ERROR = -1;
|
||||
const E_EXIST = 13900015;
|
||||
const E_URIS = 14300002;
|
||||
const E_GETRESULT = 14300004;
|
||||
let callbackFun = null;
|
||||
|
||||
export default class FileExtAbility extends Extension {
|
||||
@ -149,6 +152,7 @@ export default class FileExtAbility extends Extension {
|
||||
cb(path, true, hasNextFile);
|
||||
}
|
||||
}
|
||||
dir.closeSync();
|
||||
} else {
|
||||
cb(path, false);
|
||||
}
|
||||
@ -173,7 +177,7 @@ export default class FileExtAbility extends Extension {
|
||||
if (!this.checkUri(sourceFileUri)) {
|
||||
return {
|
||||
fd: ERR_ERROR,
|
||||
code: ERR_ERROR,
|
||||
code: E_URIS,
|
||||
};
|
||||
}
|
||||
let fd = 0;
|
||||
@ -188,7 +192,7 @@ export default class FileExtAbility extends Extension {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'openFile error ' + e.message);
|
||||
return {
|
||||
fd: ERR_ERROR,
|
||||
code: ERR_ERROR,
|
||||
code: e.code,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -197,7 +201,7 @@ export default class FileExtAbility extends Extension {
|
||||
if (!this.checkUri(parentUri)) {
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: E_URIS,
|
||||
};
|
||||
}
|
||||
try {
|
||||
@ -205,11 +209,12 @@ export default class FileExtAbility extends Extension {
|
||||
if (this.access(newFileUri).isExist) {
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: E_EXIST,
|
||||
};
|
||||
}
|
||||
let path = this.getPath(newFileUri);
|
||||
fileio.openSync(path, CREATE_FILE_FLAGS, DEFAULT_MODE);
|
||||
let fd = fileio.openSync(path, CREATE_FILE_FLAGS, DEFAULT_MODE);
|
||||
fileio.closeSync(fd);
|
||||
return {
|
||||
uri: newFileUri,
|
||||
code: ERR_OK,
|
||||
@ -218,7 +223,7 @@ export default class FileExtAbility extends Extension {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'createFile error ' + e.message);
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: e.code,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -227,7 +232,7 @@ export default class FileExtAbility extends Extension {
|
||||
if (!this.checkUri(parentUri)) {
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: E_URIS,
|
||||
};
|
||||
}
|
||||
try {
|
||||
@ -242,14 +247,14 @@ export default class FileExtAbility extends Extension {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'mkdir error ' + e.message);
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: e.code,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
delete(selectFileUri) {
|
||||
if (!this.checkUri(selectFileUri)) {
|
||||
return ERR_ERROR;
|
||||
return E_URIS;
|
||||
}
|
||||
let path = this.getPath(selectFileUri);
|
||||
let code = ERR_OK;
|
||||
@ -264,7 +269,7 @@ export default class FileExtAbility extends Extension {
|
||||
}
|
||||
} catch (e) {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'delete error ' + e.message);
|
||||
code = ERR_ERROR;
|
||||
code = e.code;
|
||||
}
|
||||
});
|
||||
return code;
|
||||
@ -274,7 +279,7 @@ export default class FileExtAbility extends Extension {
|
||||
if (!this.checkUri(sourceFileUri) || !this.checkUri(targetParentUri)) {
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: E_URIS,
|
||||
};
|
||||
}
|
||||
let displayName = this.getFileName(sourceFileUri);
|
||||
@ -291,7 +296,7 @@ export default class FileExtAbility extends Extension {
|
||||
// move to a subdirectory of the source directory
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: E_GETRESULT,
|
||||
};
|
||||
}
|
||||
try {
|
||||
@ -301,7 +306,7 @@ export default class FileExtAbility extends Extension {
|
||||
if (!stat || !stat.isDirectory()) {
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: E_GETRESULT,
|
||||
};
|
||||
}
|
||||
// If not across devices, use fileio.renameSync to move
|
||||
@ -316,10 +321,9 @@ export default class FileExtAbility extends Extension {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'move error ' + e.message);
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: e.code,
|
||||
};
|
||||
}
|
||||
let hasError = false;
|
||||
/**
|
||||
* Recursive source directory
|
||||
* If it is a directory, create a new directory first and then delete the source directory.
|
||||
@ -345,16 +349,13 @@ export default class FileExtAbility extends Extension {
|
||||
fileio.unlinkSync(filePath);
|
||||
}
|
||||
} catch (e) {
|
||||
hasError = true;
|
||||
hilog.error(DOMAIN_CODE, TAG, 'move error ' + e.message);
|
||||
return {
|
||||
uri: '',
|
||||
code: e.code,
|
||||
};
|
||||
}
|
||||
});
|
||||
if (hasError) {
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
};
|
||||
}
|
||||
return {
|
||||
uri: newFileUri,
|
||||
code: ERR_OK,
|
||||
@ -365,7 +366,7 @@ export default class FileExtAbility extends Extension {
|
||||
if (!this.checkUri(sourceFileUri)) {
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: E_URIS,
|
||||
};
|
||||
}
|
||||
try {
|
||||
@ -381,7 +382,7 @@ export default class FileExtAbility extends Extension {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'rename error ' + e.message);
|
||||
return {
|
||||
uri: '',
|
||||
code: ERR_ERROR,
|
||||
code: e.code,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -391,7 +392,7 @@ export default class FileExtAbility extends Extension {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'access checkUri fail');
|
||||
return {
|
||||
isExist: false,
|
||||
code: ERR_ERROR,
|
||||
code: E_URIS,
|
||||
};
|
||||
}
|
||||
try {
|
||||
@ -407,7 +408,7 @@ export default class FileExtAbility extends Extension {
|
||||
}
|
||||
return {
|
||||
isExist: false,
|
||||
code: ERR_ERROR,
|
||||
code: e.code,
|
||||
}
|
||||
}
|
||||
return {
|
||||
@ -420,7 +421,7 @@ export default class FileExtAbility extends Extension {
|
||||
if (!this.checkUri(sourceFileUri)) {
|
||||
return {
|
||||
infos: [],
|
||||
code: ERR_ERROR,
|
||||
code: E_URIS,
|
||||
};
|
||||
}
|
||||
let infos = [];
|
||||
@ -463,11 +464,12 @@ export default class FileExtAbility extends Extension {
|
||||
hasNextFile = false;
|
||||
}
|
||||
}
|
||||
dir.closeSync();
|
||||
} catch (e) {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'listFile error ' + e.message);
|
||||
return {
|
||||
infos: [],
|
||||
code: ERR_ERROR,
|
||||
code: e.code,
|
||||
};
|
||||
}
|
||||
return {
|
||||
@ -480,7 +482,7 @@ export default class FileExtAbility extends Extension {
|
||||
if (!this.checkUri(selectFileUri)) {
|
||||
return {
|
||||
fileInfo: {},
|
||||
code: ERR_ERROR,
|
||||
code: E_URIS,
|
||||
};
|
||||
}
|
||||
let fileInfo = {};
|
||||
@ -506,7 +508,7 @@ export default class FileExtAbility extends Extension {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'UriToFileInfo error ' + e.message);
|
||||
return {
|
||||
fileInfo: {},
|
||||
code: ERR_ERROR,
|
||||
code: e.code,
|
||||
};
|
||||
}
|
||||
return {
|
||||
|
@ -15,14 +15,21 @@
|
||||
// @ts-nocheck
|
||||
import volumeManager from '@ohos.volumeManager'
|
||||
import fileExtensionInfo from "@ohos.file.fileExtensionInfo"
|
||||
import hilog from '@ohos.hilog'
|
||||
if (!globalThis.volumeInfoList) {
|
||||
globalThis.volumeInfoList = [];
|
||||
}
|
||||
const DeviceFlag = fileExtensionInfo.DeviceFlag;
|
||||
const DeviceType = fileExtensionInfo.DeviceType;
|
||||
const DOMAIN_CODE = 0x0001;
|
||||
const TAG = 'ExternalFileManager';
|
||||
function init() {
|
||||
globalThis.volumeInfoList = [];
|
||||
volumeManager.getAllVolumes().then((volumes) => {
|
||||
volumeManager.getAllVolumes(function(error, volumes){
|
||||
if (error) {
|
||||
hilog.error(DOMAIN_CODE, TAG, 'getAllVolumes failed error message = ' + error.message);
|
||||
return;
|
||||
}
|
||||
let flags = DeviceFlag.SUPPORTS_READ | DeviceFlag.SUPPORTS_WRITE;
|
||||
for (let i = 0; i < volumes.length; i++) {
|
||||
let volume = volumes[i];
|
||||
|
@ -20,30 +20,21 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace FileAccessFwk {
|
||||
enum {
|
||||
MODULE_FILE_ACCESS_FRAMEWORK = 0x01
|
||||
};
|
||||
constexpr ErrCode BASE_OFFSET = -ErrCodeOffset(SUBSYS_FILEMANAGEMENT, MODULE_FILE_ACCESS_FRAMEWORK);
|
||||
|
||||
const int BASE_OFFSET = 14300001;
|
||||
enum {
|
||||
ERR_OK = 0,
|
||||
ERR_IPC_ERROR = BASE_OFFSET, // ipc error
|
||||
ERR_PERMISSION_DENIED, // no permission
|
||||
ERR_INVALID_URI, // invalid uri
|
||||
ERR_FILEIO_FAIL, // fileio fail
|
||||
ERR_PARAM_NUMBER, // Parameter number is abnormal
|
||||
ERR_INVALID_PARAM, // invalid parameter
|
||||
ERR_PARSER_FAIL, // parser js result error
|
||||
ERR_OPERATION_NOT_SUPPORT, // Operation not support
|
||||
ERR_GET_FILEACCESS_HELPER, // get fileAccessHelper fail
|
||||
ERR_INVALID_NOTIFY, // invalid notify
|
||||
ERR_REMOVE_NOTIFY_FAIL, // remove notify fail
|
||||
ERR_NOTIFY_NOT_EXIST, // the notify is not exist
|
||||
ERR_NOTIFY_FAIL, // notify client fail
|
||||
ERR_QUERY_EXTENSIONINFOS_FAIL, // QueryExtensionAbilityInfos fail
|
||||
ERR_PARCEL_FAIL, // parcel fail
|
||||
ERR_INVALID_RESULT, // code success result fail
|
||||
ERR_NULL_POINTER, // get value is nullptr
|
||||
E_PERMISSION_SYS = 202 // is not system app
|
||||
E_IPCS = BASE_OFFSET, // IPC error
|
||||
E_URIS, // Invalid uri
|
||||
E_GETINFO, // Fail to get fileextension info
|
||||
E_GETRESULT, // Get wrong result
|
||||
E_REGISTER, // Fail to register notification
|
||||
E_REMOVE, // Fail to remove notification
|
||||
E_INIT_NOTIFY_AGENT, // Fail to init notification agent
|
||||
E_NOTIFY, // Fail to notify agent
|
||||
E_CONNECT, // Fail to connect file access extension ability
|
||||
E_PERMISSION = 201, // Permission verification failed
|
||||
E_PERMISSION_SYS // is not system app
|
||||
};
|
||||
} // namespace FileAccessFwk
|
||||
} // namespace OHOS
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NAPI_ERROR_H
|
||||
#define NAPI_ERROR_H
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "n_napi.h"
|
||||
#include "n_error.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace FileAccessFwk {
|
||||
namespace {
|
||||
constexpr int ERRNO_NOERR = 0;
|
||||
}
|
||||
class NapiError : public OHOS::FileManagement::LibN::NError {
|
||||
public:
|
||||
NapiError(int ePosix) : errno_(ePosix) {}
|
||||
~NapiError() = default;
|
||||
void ThrowErr(napi_env env)
|
||||
{
|
||||
napi_value tmp = nullptr;
|
||||
std::string errMsg = "";
|
||||
napi_get_and_clear_last_exception(env, &tmp);
|
||||
// Note that ace engine cannot thow errors created by napi_create_error so far
|
||||
napi_status throwStatus = napi_throw_error(env, std::to_string(errno_).c_str(), errMsg.c_str());
|
||||
if (throwStatus != napi_ok) {
|
||||
HILOG_WARN("Failed to throw an exception, %{public}d, code = %{public}s",
|
||||
throwStatus, std::to_string(errno_).c_str());
|
||||
}
|
||||
}
|
||||
private:
|
||||
int errno_ = ERRNO_NOERR;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user