summaryrefslogtreecommitdiffstats
path: root/common/storage_lmdb.cpp
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2014-12-05 09:46:53 +0100
committerAaron Seigo <aseigo@kde.org>2014-12-05 09:46:53 +0100
commit351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad (patch)
tree3ba738fdc01f2b73bc3942ed530db34ef4cc1d6e /common/storage_lmdb.cpp
parent0c1400c7f0cf2f545a6cd7347314c1158fbfa36f (diff)
downloadsink-351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad.tar.gz
sink-351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad.zip
make read return a bool on success
not happy with this API, but we need to discuss the whole read thing anyways
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r--common/storage_lmdb.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 6c25448..18a5aa6 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -180,9 +180,9 @@ bool Storage::write(const std::string &sKey, const std::string &sValue)
180 return !rc; 180 return !rc;
181} 181}
182 182
183void Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) 183bool Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler)
184{ 184{
185 read(sKey, 185 return read(sKey,
186 [&](void *ptr, int size) { 186 [&](void *ptr, int size) {
187 const std::string resultValue(static_cast<char*>(ptr), size); 187 const std::string resultValue(static_cast<char*>(ptr), size);
188 resultHandler(resultValue); 188 resultHandler(resultValue);
@@ -190,10 +190,10 @@ void Storage::read(const std::string &sKey, const std::function<void(const std::
190// std::cout << "key: " << resultKey << " data: " << resultValue << std::endl; 190// std::cout << "key: " << resultKey << " data: " << resultValue << std::endl;
191} 191}
192 192
193void Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) 193bool Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler)
194{ 194{
195 if (!d->env) { 195 if (!d->env) {
196 return; 196 return false;
197 } 197 }
198 198
199 int rc; 199 int rc;
@@ -208,14 +208,14 @@ void Storage::read(const std::string &sKey, const std::function<void(void *ptr,
208 if (implicitTransaction) { 208 if (implicitTransaction) {
209 // TODO: if this fails, still try the write below? 209 // TODO: if this fails, still try the write below?
210 if (!startTransaction(ReadOnly)) { 210 if (!startTransaction(ReadOnly)) {
211 return; 211 return false;
212 } 212 }
213 } 213 }
214 214
215 rc = mdb_cursor_open(d->transaction, d->dbi, &cursor); 215 rc = mdb_cursor_open(d->transaction, d->dbi, &cursor);
216 if (rc) { 216 if (rc) {
217 std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; 217 std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl;
218 return; 218 return false;
219 } 219 }
220 220
221 if (sKey.empty()) { 221 if (sKey.empty()) {
@@ -237,18 +237,20 @@ void Storage::read(const std::string &sKey, const std::function<void(void *ptr,
237 } 237 }
238 } 238 }
239 239
240 mdb_cursor_close(cursor);
241
240 if (rc) { 242 if (rc) {
241 std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl; 243 std::cerr << "mdb_cursor_get: " << rc << " " << mdb_strerror(rc) << std::endl;
244 return false
242 } 245 }
243 246
244 mdb_cursor_close(cursor);
245
246 /** 247 /**
247 we don't abort the transaction since we need it for reading the values 248 we don't abort the transaction since we need it for reading the values
248 if (implicitTransaction) { 249 if (implicitTransaction) {
249 abortTransaction(); 250 abortTransaction();
250 } 251 }
251 */ 252 */
253 return true;
252} 254}
253 255
254qint64 Storage::diskUsage() const 256qint64 Storage::diskUsage() const