summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-20 20:42:52 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-23 17:37:53 +0200
commit166aa563ad41c4566c02cff583df612e328d1520 (patch)
tree2acf8397e03d464dae2d451ce3b7a36d2c439691
parent3c3c117b96f0063221889d3e896cdbadd1b36a99 (diff)
downloadsink-166aa563ad41c4566c02cff583df612e328d1520.tar.gz
sink-166aa563ad41c4566c02cff583df612e328d1520.zip
Deal with non-existing index
-rw-r--r--common/index.cpp4
-rw-r--r--common/index.h4
-rw-r--r--examples/dummyresource/resourcefactory.cpp21
3 files changed, 17 insertions, 12 deletions
diff --git a/common/index.cpp b/common/index.cpp
index 9bb467b..a8de697 100644
--- a/common/index.cpp
+++ b/common/index.cpp
@@ -17,6 +17,10 @@ void Index::add(const QByteArray &key, const QByteArray &value)
17void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, 17void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler,
18 const std::function<void(const Error &error)> &errorHandler) 18 const std::function<void(const Error &error)> &errorHandler)
19{ 19{
20 if (!mStorage.exists()) {
21 errorHandler(Error("index", IndexNotAvailable, "Index not existing"));
22 return;
23 }
20 mStorage.scan(key, [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { 24 mStorage.scan(key, [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool {
21 resultHandler(QByteArray(static_cast<char*>(valuePtr), valueSize)); 25 resultHandler(QByteArray(static_cast<char*>(valuePtr), valueSize));
22 return true; 26 return true;
diff --git a/common/index.h b/common/index.h
index 3cd7cc8..08b499f 100644
--- a/common/index.h
+++ b/common/index.h
@@ -11,6 +11,10 @@
11class Index 11class Index
12{ 12{
13public: 13public:
14 enum ErrorCodes {
15 IndexNotAvailable = -1
16 };
17
14 class Error 18 class Error
15 { 19 {
16 public: 20 public:
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp
index b9123d5..c7a3eef 100644
--- a/examples/dummyresource/resourcefactory.cpp
+++ b/examples/dummyresource/resourcefactory.cpp
@@ -66,22 +66,20 @@ void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline)
66KAsync::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeline) 66KAsync::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeline)
67{ 67{
68 return KAsync::start<void>([this, pipeline](KAsync::Future<void> &f) { 68 return KAsync::start<void>([this, pipeline](KAsync::Future<void> &f) {
69 auto storage = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier); 69 //TODO start transaction on index
70 storage->startTransaction(Akonadi2::Storage::ReadOnly);
71
72 Index uidIndex(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier + ".index.uid", Akonadi2::Storage::ReadOnly); 70 Index uidIndex(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier + ".index.uid", Akonadi2::Storage::ReadOnly);
73 71
74 const auto data = DummyStore::instance().data(); 72 const auto data = DummyStore::instance().data();
75 for (auto it = data.constBegin(); it != data.constEnd(); it++) { 73 for (auto it = data.constBegin(); it != data.constEnd(); it++) {
76 bool isNew = true; 74 bool isNew = true;
77 if (storage->exists()) { 75 uidIndex.lookup(it.key().toLatin1(), [&](const QByteArray &value) {
78 uidIndex.lookup(it.key().toLatin1(), [&](const QByteArray &value) { 76 isNew = false;
79 isNew = false; 77 },
80 }, 78 [](const Index::Error &error) {
81 [](const Index::Error &error) { 79 if (error.code != Index::IndexNotAvailable) {
82 Warning() << "Error in index: " << error.message; 80 Warning() << "Error in uid index: " << error.message;
83 }); 81 }
84 } 82 });
85 if (isNew) { 83 if (isNew) {
86 m_fbb.Clear(); 84 m_fbb.Clear();
87 85
@@ -117,7 +115,6 @@ KAsync::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipel
117 //TODO diff and create modification if necessary 115 //TODO diff and create modification if necessary
118 } 116 }
119 } 117 }
120 storage->abortTransaction();
121 //TODO find items to remove 118 //TODO find items to remove
122 f.setFinished(); 119 f.setFinished();
123 }); 120 });