diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-29 17:52:45 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-10-29 17:52:45 +0100 |
commit | 0a2d20c474206553d5c981fd2a772188083101e9 (patch) | |
tree | 37a46837b4fa93834a9380ee02ef4188786e9acd /common | |
parent | 70faf80be4146b17a59f9616404b21625d7400f6 (diff) | |
download | sink-0a2d20c474206553d5c981fd2a772188083101e9.tar.gz sink-0a2d20c474206553d5c981fd2a772188083101e9.zip |
Updated the index on modifications and removals.
Misses tests.
Diffstat (limited to 'common')
-rw-r--r-- | common/index.cpp | 5 | ||||
-rw-r--r-- | common/index.h | 2 | ||||
-rw-r--r-- | common/storage.h | 8 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 17 |
4 files changed, 27 insertions, 5 deletions
diff --git a/common/index.cpp b/common/index.cpp index f752f5f..2fc0fe3 100644 --- a/common/index.cpp +++ b/common/index.cpp | |||
@@ -19,6 +19,11 @@ void Index::add(const QByteArray &key, const QByteArray &value) | |||
19 | mDb.write(key, value); | 19 | mDb.write(key, value); |
20 | } | 20 | } |
21 | 21 | ||
22 | void Index::remove(const QByteArray &key, const QByteArray &value) | ||
23 | { | ||
24 | mDb.remove(key, value); | ||
25 | } | ||
26 | |||
22 | void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, | 27 | void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, |
23 | const std::function<void(const Error &error)> &errorHandler) | 28 | const std::function<void(const Error &error)> &errorHandler) |
24 | { | 29 | { |
diff --git a/common/index.h b/common/index.h index e1b7e3a..0ca32af 100644 --- a/common/index.h +++ b/common/index.h | |||
@@ -29,7 +29,7 @@ public: | |||
29 | Index(const QByteArray &name, Akonadi2::Storage::Transaction &); | 29 | Index(const QByteArray &name, Akonadi2::Storage::Transaction &); |
30 | 30 | ||
31 | void add(const QByteArray &key, const QByteArray &value); | 31 | void add(const QByteArray &key, const QByteArray &value); |
32 | // void remove(const QByteArray &key, const QByteArray &value); | 32 | void remove(const QByteArray &key, const QByteArray &value); |
33 | 33 | ||
34 | void lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, | 34 | void lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, |
35 | const std::function<void(const Error &error)> &errorHandler); | 35 | const std::function<void(const Error &error)> &errorHandler); |
diff --git a/common/storage.h b/common/storage.h index aa0be4c..a4137ce 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -63,11 +63,17 @@ public: | |||
63 | bool write(const QByteArray &key, const QByteArray &value, const std::function<void(const Storage::Error &error)> &errorHandler = std::function<void(const Storage::Error &error)>()); | 63 | bool write(const QByteArray &key, const QByteArray &value, const std::function<void(const Storage::Error &error)> &errorHandler = std::function<void(const Storage::Error &error)>()); |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Remove a value | 66 | * Remove a key |
67 | */ | 67 | */ |
68 | void remove(const QByteArray &key, | 68 | void remove(const QByteArray &key, |
69 | const std::function<void(const Storage::Error &error)> &errorHandler = std::function<void(const Storage::Error &error)>()); | 69 | const std::function<void(const Storage::Error &error)> &errorHandler = std::function<void(const Storage::Error &error)>()); |
70 | /** | 70 | /** |
71 | * Remove a key-value pair | ||
72 | */ | ||
73 | void remove(const QByteArray &key, const QByteArray &value, | ||
74 | const std::function<void(const Storage::Error &error)> &errorHandler = std::function<void(const Storage::Error &error)>()); | ||
75 | |||
76 | /** | ||
71 | * Read values with a given key. | 77 | * Read values with a given key. |
72 | * | 78 | * |
73 | * * An empty @param key results in a full scan | 79 | * * An empty @param key results in a full scan |
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index be5a9da..1516e69 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -149,6 +149,12 @@ bool Storage::NamedDatabase::write(const QByteArray &sKey, const QByteArray &sVa | |||
149 | void Storage::NamedDatabase::remove(const QByteArray &k, | 149 | void Storage::NamedDatabase::remove(const QByteArray &k, |
150 | const std::function<void(const Storage::Error &error)> &errorHandler) | 150 | const std::function<void(const Storage::Error &error)> &errorHandler) |
151 | { | 151 | { |
152 | remove(k, QByteArray(), errorHandler); | ||
153 | } | ||
154 | |||
155 | void Storage::NamedDatabase::remove(const QByteArray &k, const QByteArray &value, | ||
156 | const std::function<void(const Storage::Error &error)> &errorHandler) | ||
157 | { | ||
152 | if (!d || !d->transaction) { | 158 | if (!d || !d->transaction) { |
153 | Error error(d->name.toLatin1(), ErrorCodes::GenericError, "Not open"); | 159 | Error error(d->name.toLatin1(), ErrorCodes::GenericError, "Not open"); |
154 | if (d) { | 160 | if (d) { |
@@ -161,14 +167,19 @@ void Storage::NamedDatabase::remove(const QByteArray &k, | |||
161 | MDB_val key; | 167 | MDB_val key; |
162 | key.mv_size = k.size(); | 168 | key.mv_size = k.size(); |
163 | key.mv_data = const_cast<void*>(static_cast<const void*>(k.data())); | 169 | key.mv_data = const_cast<void*>(static_cast<const void*>(k.data())); |
164 | rc = mdb_del(d->transaction, d->dbi, &key, 0); | 170 | if (value.isEmpty()) { |
171 | rc = mdb_del(d->transaction, d->dbi, &key, 0); | ||
172 | } else { | ||
173 | MDB_val data; | ||
174 | data.mv_size = value.size(); | ||
175 | data.mv_data = const_cast<void*>(static_cast<const void*>(value.data())); | ||
176 | rc = mdb_del(d->transaction, d->dbi, &key, &data); | ||
177 | } | ||
165 | 178 | ||
166 | if (rc) { | 179 | if (rc) { |
167 | Error error(d->name.toLatin1(), ErrorCodes::GenericError, QString("Error on mdb_del: %1 %2").arg(rc).arg(mdb_strerror(rc)).toLatin1()); | 180 | Error error(d->name.toLatin1(), ErrorCodes::GenericError, QString("Error on mdb_del: %1 %2").arg(rc).arg(mdb_strerror(rc)).toLatin1()); |
168 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); | 181 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); |
169 | } | 182 | } |
170 | |||
171 | return; | ||
172 | } | 183 | } |
173 | 184 | ||
174 | int Storage::NamedDatabase::scan(const QByteArray &k, | 185 | int Storage::NamedDatabase::scan(const QByteArray &k, |