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 if (val == -1) {
38 return E_RDB;
39 }
40 return E_OK;
41 }
42
GetLong(const string & key,int64_t & val,const shared_ptr<ResultSet> resultSet)43 int32_t CloudDiskRdbUtils::GetLong(const string &key, int64_t &val,
44 const shared_ptr<ResultSet> resultSet)
45 {
46 return E_OK;
47 }
48
GetString(const string & key,string & val,const shared_ptr<ResultSet> resultSet)49 int32_t CloudDiskRdbUtils::GetString(const string &key, string &val,
50 const shared_ptr<ResultSet> resultSet)
51 {
52 if (val == "mock") {
53 return E_RDB;
54 }
55 return E_OK;
56 }
57
FillFileInfo(const RowEntity & rowEntity,CloudDiskFileInfo & info)58 static void FillFileInfo(const RowEntity &rowEntity, CloudDiskFileInfo &info)
59 {
60 rowEntity.Get(FileColumn::FILE_NAME).GetString(info.name);
61 rowEntity.Get(FileColumn::CLOUD_ID).GetString(info.cloudId);
62 rowEntity.Get(FileColumn::PARENT_CLOUD_ID).GetString(info.parentCloudId);
63 int32_t int_variable;
64 rowEntity.Get(FileColumn::POSITION).GetInt(int_variable);
65 info.location = static_cast<uint32_t>(int_variable);
66 int64_t long_variable;
67 rowEntity.Get(FileColumn::FILE_SIZE).GetLong(long_variable);
68 info.size = static_cast<unsigned long long>(long_variable);
69 rowEntity.Get(FileColumn::FILE_TIME_ADDED).GetLong(long_variable);
70 info.atime = static_cast<unsigned long long>(long_variable);
71 rowEntity.Get(FileColumn::META_TIME_EDITED).GetLong(long_variable);
72 info.ctime = static_cast<unsigned long long>(long_variable);
73 rowEntity.Get(FileColumn::FILE_TIME_EDITED).GetLong(long_variable);
74 info.mtime = static_cast<unsigned long long>(long_variable);
75 rowEntity.Get(FileColumn::IS_DIRECTORY).GetInt(int_variable);
76 info.IsDirectory = (int_variable == DIRECTORY);
77 rowEntity.Get(FileColumn::ROW_ID).GetLong(long_variable);
78 info.localId = static_cast<long long>(long_variable) + LOCAL_ID_OFFSET;
79 }
80
ResultSetToFileInfo(const shared_ptr<ResultSet> resultSet,CloudDiskFileInfo & info)81 int32_t CloudDiskRdbUtils::ResultSetToFileInfo(const shared_ptr<ResultSet> resultSet,
82 CloudDiskFileInfo &info)
83 {
84 if (info.name == "mock") {
85 return E_RDB;
86 }
87 return E_OK;
88 }
89
FuseDentryAlignSize(const char * name)90 size_t CloudDiskRdbUtils::FuseDentryAlignSize(const char *name)
91 {
92 return fuse_add_direntry({}, nullptr, 0, name, nullptr, 0);
93 }
94
ResultSetToFileInfos(const shared_ptr<ResultSet> resultSet,vector<CloudDiskFileInfo> & infos)95 int32_t CloudDiskRdbUtils::ResultSetToFileInfos(const shared_ptr<ResultSet> resultSet,
96 vector<CloudDiskFileInfo> &infos)
97 {
98 if (infos.empty()) {
99 return E_RDB;
100 }
101 return E_OK;
102 }
103 }