1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #define FUSE_USE_VERSION 34
17
18 #include "clouddisk_rdb_utils.h"
19
20 #include <fuse_lowlevel.h>
21
22 #include "utils_log.h"
23 #include "dfs_error.h"
24 #include "clouddisk_db_const.h"
25 #include "file_column.h"
26 #include "result_set.h"
27
28 namespace OHOS::FileManagement::CloudDisk {
29 using namespace std;
30 using namespace NativeRdb;
31
32 static const int32_t LOCAL_ID_OFFSET = 100;
33
GetInt(const string & key,int32_t & val,const shared_ptr<ResultSet> resultSet)34 int32_t CloudDiskRdbUtils::GetInt(const string &key, int32_t &val,
35 const shared_ptr<ResultSet> resultSet)
36 {
37 return E_OK;
38 }
39
GetLong(const string & key,int64_t & val,const shared_ptr<ResultSet> resultSet)40 int32_t CloudDiskRdbUtils::GetLong(const string &key, int64_t &val,
41 const shared_ptr<ResultSet> resultSet)
42 {
43 return E_OK;
44 }
45
GetString(const string & key,string & val,const shared_ptr<ResultSet> resultSet)46 int32_t CloudDiskRdbUtils::GetString(const string &key, string &val,
47 const shared_ptr<ResultSet> resultSet)
48 {
49 if (val == "mock") {
50 return E_RDB;
51 }
52 return E_OK;
53 }
54
FillFileInfo(const RowEntity & rowEntity,CloudDiskFileInfo & info)55 static void FillFileInfo(const RowEntity &rowEntity, CloudDiskFileInfo &info)
56 {
57 rowEntity.Get(FileColumn::FILE_NAME).GetString(info.name);
58 rowEntity.Get(FileColumn::CLOUD_ID).GetString(info.cloudId);
59 rowEntity.Get(FileColumn::PARENT_CLOUD_ID).GetString(info.parentCloudId);
60 int32_t int_variable;
61 rowEntity.Get(FileColumn::POSITION).GetInt(int_variable);
62 info.location = static_cast<uint32_t>(int_variable);
63 int64_t long_variable;
64 rowEntity.Get(FileColumn::FILE_SIZE).GetLong(long_variable);
65 info.size = static_cast<unsigned long long>(long_variable);
66 rowEntity.Get(FileColumn::FILE_TIME_ADDED).GetLong(long_variable);
67 info.atime = static_cast<unsigned long long>(long_variable);
68 rowEntity.Get(FileColumn::META_TIME_EDITED).GetLong(long_variable);
69 info.ctime = static_cast<unsigned long long>(long_variable);
70 rowEntity.Get(FileColumn::FILE_TIME_EDITED).GetLong(long_variable);
71 info.mtime = static_cast<unsigned long long>(long_variable);
72 rowEntity.Get(FileColumn::IS_DIRECTORY).GetInt(int_variable);
73 info.IsDirectory = (int_variable == DIRECTORY);
74 rowEntity.Get(FileColumn::ROW_ID).GetLong(long_variable);
75 info.localId = static_cast<long long>(long_variable) + LOCAL_ID_OFFSET;
76 }
77
ResultSetToFileInfo(const shared_ptr<ResultSet> resultSet,CloudDiskFileInfo & info)78 int32_t CloudDiskRdbUtils::ResultSetToFileInfo(const shared_ptr<ResultSet> resultSet,
79 CloudDiskFileInfo &info)
80 {
81 if (info.name == "mock") {
82 return E_RDB;
83 }
84 return E_OK;
85 }
86
FuseDentryAlignSize(const char * name)87 size_t CloudDiskRdbUtils::FuseDentryAlignSize(const char *name)
88 {
89 return fuse_add_direntry({}, nullptr, 0, name, nullptr, 0);
90 }
91
ResultSetToFileInfos(const shared_ptr<ResultSet> resultSet,vector<CloudDiskFileInfo> & infos)92 int32_t CloudDiskRdbUtils::ResultSetToFileInfos(const shared_ptr<ResultSet> resultSet,
93 vector<CloudDiskFileInfo> &infos)
94 {
95 if (infos.empty()) {
96 return E_RDB;
97 }
98 return E_OK;
99 }
100 }