From 768c1077b0d226d832f34904e929c2462eca158f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 16 Feb 2017 10:29:27 +0100 Subject: Remember whether a blob property is external or not. ...we used to accidentally move external blobs after the property was lost when storing the modificatoin in the queue. --- common/domain/applicationdomaintype.h | 2 +- common/propertymapper.cpp | 12 ++++++++++-- common/storage/entitystore.cpp | 1 + tests/mailsynctest.cpp | 16 +++++++++++----- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 98b7de7..7380c04 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -280,7 +280,7 @@ inline QDebug operator<< (QDebug d, const Reference &ref) inline QDebug operator<< (QDebug d, const BLOB &blob) { - d << blob.value; + d << blob.value << "external:" << blob.isExternal ; return d; } diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index 4cfe154..4d45644 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp @@ -36,7 +36,9 @@ template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) { if (property.isValid()) { - return fbb.CreateString(property.value().value.toStdString()).o; + const auto blob = property.value(); + auto s = blob.value + (blob.isExternal ? ":ext" : ":int"); + return fbb.CreateString(s.toStdString()).o; } return 0; } @@ -133,7 +135,13 @@ QVariant propertyToVariant(const flatbuffers::Str { if (property) { // We have to copy the memory, otherwise it would become eventually invalid - return QVariant::fromValue(Sink::ApplicationDomain::BLOB{QString::fromStdString(property->c_str())}); + auto s = QString::fromStdString(property->c_str()); + auto ext = s.endsWith(":ext"); + s.chop(4); + + auto blob = Sink::ApplicationDomain::BLOB{s}; + blob.isExternal = ext; + return QVariant::fromValue(blob); } return QVariant(); } diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 51e5da7..9156dd4 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -162,6 +162,7 @@ void EntityStore::copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qi SinkWarningCtx(d->logCtx) << "Failed to move the file from: " << oldPath << " to " << filePath << ". " << origFile.errorString(); } origFile.close(); + SinkTraceCtx(d->logCtx) << "Moved blob property: " << property << " from " << oldPath << "to" << filePath; entity.setProperty(property, QVariant::fromValue(ApplicationDomain::BLOB{filePath})); } } diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index d3b0fe3..3e5a928 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp @@ -271,16 +271,17 @@ void MailSyncTest::testListMails() auto job = Store::fetchAll(query).then([](const QList &mails) { QCOMPARE(mails.size(), 1); - QVERIFY(mails.first()->getSubject().startsWith(QString("[Nepomuk] Jenkins build is still unstable"))); - const auto data = mails.first()->getMimeMessage(); + auto mail = mails.first(); + QVERIFY(mail->getSubject().startsWith(QString("[Nepomuk] Jenkins build is still unstable"))); + const auto data = mail->getMimeMessage(); QVERIFY(!data.isEmpty()); KMime::Message m; m.setContent(data); m.parse(); - QCOMPARE(mails.first()->getSubject(), m.subject(true)->asUnicodeString()); - QVERIFY(!mails.first()->getFolder().isEmpty()); - QVERIFY(mails.first()->getDate().isValid()); + QCOMPARE(mail->getSubject(), m.subject(true)->asUnicodeString()); + QVERIFY(!mail->getFolder().isEmpty()); + QVERIFY(mail->getDate().isValid()); }); VERIFYEXEC(job); } @@ -289,6 +290,8 @@ void MailSyncTest::testResyncMails() { Sink::Query query; query.resourceFilter(mResourceInstanceIdentifier); + query.request(); + query.request(); // Ensure all local data is processed VERIFYEXEC(Store::synchronize(query)); @@ -300,6 +303,9 @@ void MailSyncTest::testResyncMails() auto job = Store::fetchAll(query).then([](const QList &mails) { QCOMPARE(mails.size(), 1); + auto mail = mails.first(); + QVERIFY(!mail->getSubject().isEmpty()); + QVERIFY(!mail->getMimeMessagePath().isEmpty()); }); VERIFYEXEC(job); } -- cgit v1.2.3