• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "include/store_util_mock.h"
17 #include "types.h"
18 
19 namespace OHOS::DistributedKv {
20 
IsFileExist(const std::string & name)21 bool StoreUtil::IsFileExist(const std::string &name)
22 {
23     if (BStoreUtil::storeUtil == nullptr) {
24         return false;
25     }
26     return BStoreUtil::storeUtil->IsFileExist(name);
27 }
28 
Remove(const std::string & path)29 bool StoreUtil::Remove(const std::string &path)
30 {
31     if (BStoreUtil::storeUtil == nullptr) {
32         return false;
33     }
34     return BStoreUtil::storeUtil->Remove(path);
35 }
36 
ConvertStatus(StoreUtil::DBStatus status)37 Status StoreUtil::ConvertStatus(StoreUtil::DBStatus status)
38 {
39     if (BStoreUtil::storeUtil == nullptr) {
40         return Status::ERROR;
41     }
42     return BStoreUtil::storeUtil->ConvertStatus(status);
43 }
44 
GetDBSecurity(int32_t secLevel)45 StoreUtil::DBSecurity StoreUtil::GetDBSecurity(int32_t secLevel)
46 {
47     if (BStoreUtil::storeUtil == nullptr) {
48         return { DistributedDB::NOT_SET, DistributedDB::ECE };
49     }
50     return BStoreUtil::storeUtil->GetDBSecurity(secLevel);
51 }
52 
InitPath(const std::string & path)53 bool StoreUtil::InitPath(const std::string &path)
54 {
55     if (BStoreUtil::storeUtil == nullptr) {
56         return false;
57     }
58     return BStoreUtil::storeUtil->InitPath(path);
59 }
60 
GetDBIndexType(IndexType type)61 StoreUtil::DBIndexType StoreUtil::GetDBIndexType(IndexType type)
62 {
63     if (BStoreUtil::storeUtil == nullptr) {
64         return DistributedDB::HASH;
65     }
66     return BStoreUtil::storeUtil->GetDBIndexType(type);
67 }
68 
GetSubPath(const std::string & path)69 std::vector<std::string> StoreUtil::GetSubPath(const std::string &path)
70 {
71     if (BStoreUtil::storeUtil == nullptr) {
72         std::vector<std::string> vec;
73         return vec;
74     }
75     return BStoreUtil::storeUtil->GetSubPath(path);
76 }
77 
GetFiles(const std::string & path)78 std::vector<StoreUtil::FileInfo> StoreUtil::GetFiles(const std::string &path)
79 {
80     if (BStoreUtil::storeUtil == nullptr) {
81         std::vector<StoreUtil::FileInfo> fileInfos;
82         return fileInfos;
83     }
84     return BStoreUtil::storeUtil->GetFiles(path);
85 }
86 
Rename(const std::string & oldName,const std::string & newName)87 bool StoreUtil::Rename(const std::string &oldName, const std::string &newName)
88 {
89     if (BStoreUtil::storeUtil == nullptr) {
90         return false;
91     }
92     return BStoreUtil::storeUtil->Rename(oldName, newName);
93 }
94 
Anonymous(const std::string & name)95 std::string StoreUtil::Anonymous(const std::string &name)
96 {
97     if (BStoreUtil::storeUtil == nullptr) {
98         return "";
99     }
100     return BStoreUtil::storeUtil->Anonymous(name);
101 }
102 
Anonymous(const void * ptr)103 uint32_t StoreUtil::Anonymous(const void *ptr)
104 {
105     if (BStoreUtil::storeUtil == nullptr) {
106         return 0;
107     }
108     return BStoreUtil::storeUtil->Anonymous(ptr);
109 }
110 
RemoveRWXForOthers(const std::string & path)111 bool StoreUtil::RemoveRWXForOthers(const std::string &path)
112 {
113     if (BStoreUtil::storeUtil == nullptr) {
114         return false;
115     }
116     return BStoreUtil::storeUtil->RemoveRWXForOthers(path);
117 }
118 
CreateFile(const std::string & name)119 bool StoreUtil::CreateFile(const std::string &name)
120 {
121     if (BStoreUtil::storeUtil == nullptr) {
122         return false;
123     }
124     return BStoreUtil::storeUtil->CreateFile(name);
125 }
126 
Flush()127 void StoreUtil::Flush()
128 {
129 }
130 
GetSecLevel(StoreUtil::DBSecurity dbSec)131 int32_t StoreUtil::GetSecLevel(StoreUtil::DBSecurity dbSec)
132 {
133     return NO_LABEL;
134 }
135 
GenSequenceId()136 uint64_t StoreUtil::GenSequenceId()
137 {
138     return 0;
139 }
140 
GetDBMode(SyncMode syncMode)141 StoreUtil::DBMode StoreUtil::GetDBMode(SyncMode syncMode)
142 {
143     DBMode dbMode = DBMode::SYNC_MODE_PULL_ONLY;
144     return dbMode;
145 }
146 } // namespace OHOS::DistributedKv