diff options
-rw-r--r-- | common/genericresource.cpp | 20 | ||||
-rw-r--r-- | common/genericresource.h | 4 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 14 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.h | 2 |
4 files changed, 29 insertions, 11 deletions
diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 1af9226..9fbcaaa 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp | |||
@@ -370,6 +370,26 @@ void GenericResource::processCommand(int commandId, const QByteArray &data) | |||
370 | } | 370 | } |
371 | } | 371 | } |
372 | 372 | ||
373 | KAsync::Job<void> GenericResource::synchronizeWithSource() | ||
374 | { | ||
375 | return KAsync::start<void>([this]() { | ||
376 | Log() << " Synchronizing"; | ||
377 | //Changereplay would deadlock otherwise when trying to open the synchronization store | ||
378 | enableChangeReplay(false); | ||
379 | auto mainStore = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier, Akonadi2::Storage::ReadOnly); | ||
380 | auto syncStore = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); | ||
381 | synchronizeWithSource(*mainStore, *syncStore).then<void>([this, mainStore, syncStore]() { | ||
382 | Log() << "Done Synchronizing"; | ||
383 | enableChangeReplay(true); | ||
384 | }).exec(); | ||
385 | }); | ||
386 | } | ||
387 | |||
388 | KAsync::Job<void> GenericResource::synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) | ||
389 | { | ||
390 | return KAsync::null<void>(); | ||
391 | } | ||
392 | |||
373 | static void waitForDrained(KAsync::Future<void> &f, MessageQueue &queue) | 393 | static void waitForDrained(KAsync::Future<void> &f, MessageQueue &queue) |
374 | { | 394 | { |
375 | if (queue.isEmpty()) { | 395 | if (queue.isEmpty()) { |
diff --git a/common/genericresource.h b/common/genericresource.h index 9c8b977..ea68a25 100644 --- a/common/genericresource.h +++ b/common/genericresource.h | |||
@@ -44,7 +44,8 @@ public: | |||
44 | virtual ~GenericResource(); | 44 | virtual ~GenericResource(); |
45 | 45 | ||
46 | virtual void processCommand(int commandId, const QByteArray &data) Q_DECL_OVERRIDE; | 46 | virtual void processCommand(int commandId, const QByteArray &data) Q_DECL_OVERRIDE; |
47 | virtual KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE = 0; | 47 | virtual KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE; |
48 | virtual KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore); | ||
48 | virtual KAsync::Job<void> processAllMessages() Q_DECL_OVERRIDE; | 49 | virtual KAsync::Job<void> processAllMessages() Q_DECL_OVERRIDE; |
49 | virtual void setLowerBoundRevision(qint64 revision) Q_DECL_OVERRIDE; | 50 | virtual void setLowerBoundRevision(qint64 revision) Q_DECL_OVERRIDE; |
50 | 51 | ||
@@ -52,6 +53,7 @@ public: | |||
52 | 53 | ||
53 | static void removeFromDisk(const QByteArray &instanceIdentifier); | 54 | static void removeFromDisk(const QByteArray &instanceIdentifier); |
54 | static qint64 diskUsage(const QByteArray &instanceIdentifier); | 55 | static qint64 diskUsage(const QByteArray &instanceIdentifier); |
56 | |||
55 | private Q_SLOTS: | 57 | private Q_SLOTS: |
56 | void updateLowerBoundRevision(); | 58 | void updateLowerBoundRevision(); |
57 | 59 | ||
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 45ee8c1..6c6c5aa 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -344,28 +344,24 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti | |||
344 | } | 344 | } |
345 | } | 345 | } |
346 | 346 | ||
347 | KAsync::Job<void> MaildirResource::synchronizeWithSource() | 347 | KAsync::Job<void> MaildirResource::synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) |
348 | { | 348 | { |
349 | Log() << " Synchronizing"; | 349 | Log() << " Synchronizing"; |
350 | return KAsync::start<void>([this]() { | 350 | return KAsync::start<void>([this, &mainStore, &synchronizationStore]() { |
351 | //Changereplay would deadlock otherwise when trying to open the synchronization store | 351 | auto transaction = mainStore.createTransaction(Akonadi2::Storage::ReadOnly); |
352 | enableChangeReplay(false); | ||
353 | auto transaction = Akonadi2::Storage(Akonadi2::storageLocation(), mResourceInstanceIdentifier, Akonadi2::Storage::ReadOnly).createTransaction(Akonadi2::Storage::ReadOnly); | ||
354 | Akonadi2::Storage store(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); | ||
355 | { | 352 | { |
356 | auto synchronizationTransaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | 353 | auto synchronizationTransaction = synchronizationStore.createTransaction(Akonadi2::Storage::ReadWrite); |
357 | synchronizeFolders(transaction, synchronizationTransaction); | 354 | synchronizeFolders(transaction, synchronizationTransaction); |
358 | //The next sync needs the folders available | 355 | //The next sync needs the folders available |
359 | synchronizationTransaction.commit(); | 356 | synchronizationTransaction.commit(); |
360 | } | 357 | } |
361 | for (const auto &folder : listAvailableFolders()) { | 358 | for (const auto &folder : listAvailableFolders()) { |
362 | auto synchronizationTransaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | 359 | auto synchronizationTransaction = synchronizationStore.createTransaction(Akonadi2::Storage::ReadWrite); |
363 | synchronizeMails(transaction, synchronizationTransaction, folder); | 360 | synchronizeMails(transaction, synchronizationTransaction, folder); |
364 | //Don't let the transaction grow too much | 361 | //Don't let the transaction grow too much |
365 | synchronizationTransaction.commit(); | 362 | synchronizationTransaction.commit(); |
366 | } | 363 | } |
367 | Log() << "Done Synchronizing"; | 364 | Log() << "Done Synchronizing"; |
368 | enableChangeReplay(true); | ||
369 | }); | 365 | }); |
370 | } | 366 | } |
371 | 367 | ||
diff --git a/examples/maildirresource/maildirresource.h b/examples/maildirresource/maildirresource.h index b3ceefa..9c205c8 100644 --- a/examples/maildirresource/maildirresource.h +++ b/examples/maildirresource/maildirresource.h | |||
@@ -35,7 +35,7 @@ class MaildirResource : public Akonadi2::GenericResource | |||
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | MaildirResource(const QByteArray &instanceIdentifier, const QSharedPointer<Akonadi2::Pipeline> &pipeline = QSharedPointer<Akonadi2::Pipeline>()); | 37 | MaildirResource(const QByteArray &instanceIdentifier, const QSharedPointer<Akonadi2::Pipeline> &pipeline = QSharedPointer<Akonadi2::Pipeline>()); |
38 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE; | 38 | KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; |
39 | static void removeFromDisk(const QByteArray &instanceIdentifier); | 39 | static void removeFromDisk(const QByteArray &instanceIdentifier); |
40 | private: | 40 | private: |
41 | KAsync::Job<void> replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; | 41 | KAsync::Job<void> replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; |