summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-07 00:01:54 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-07 00:01:54 +0100
commit88a0c750a80e6efb207877cac73144266e62d5ff (patch)
treefef58a156cc7dbb23dff8ccdfbcf13a7fb3ed467
parent57445759ee3c26dd03aa8292be3187685a424c1d (diff)
downloadsink-88a0c750a80e6efb207877cac73144266e62d5ff.tar.gz
sink-88a0c750a80e6efb207877cac73144266e62d5ff.zip
Move blob files on move to the same location like when a client moves.
Otherwise if the source resource manages to clean up the revision before the target resource gets to process the new entity, then the blob file is gone already.
-rw-r--r--common/domain/applicationdomaintype.cpp6
-rw-r--r--tests/interresourcemovetest.cpp37
2 files changed, 28 insertions, 15 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index fd88570..99f14a1 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -115,10 +115,8 @@ void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::Applicatio
115 for (const auto &property : propertiesToCopy) { 115 for (const auto &property : propertiesToCopy) {
116 const auto value = buffer.getProperty(property); 116 const auto value = buffer.getProperty(property);
117 if (copyBlobs && value.canConvert<BLOB>()) { 117 if (copyBlobs && value.canConvert<BLOB>()) {
118 auto oldPath = value.value<BLOB>().value; 118 const auto oldPath = value.value<BLOB>().value;
119 //FIXME: This is neither pretty nor save if we have multiple modifications of the same property (the first modification will remove the file). 119 const auto newPath = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString();
120 //At least if the modification fails the file will be removed once the entity is removed.
121 auto newPath = oldPath + "copy";
122 QFile::copy(oldPath, newPath); 120 QFile::copy(oldPath, newPath);
123 memoryAdaptor.setProperty(property, QVariant::fromValue(BLOB{newPath})); 121 memoryAdaptor.setProperty(property, QVariant::fromValue(BLOB{newPath}));
124 } else if (pruneReferences && value.canConvert<Reference>()) { 122 } else if (pruneReferences && value.canConvert<Reference>()) {
diff --git a/tests/interresourcemovetest.cpp b/tests/interresourcemovetest.cpp
index 7561c5b..3ac6ad4 100644
--- a/tests/interresourcemovetest.cpp
+++ b/tests/interresourcemovetest.cpp
@@ -28,6 +28,7 @@
28#include "log.h" 28#include "log.h"
29#include "test.h" 29#include "test.h"
30#include "testutils.h" 30#include "testutils.h"
31#include <KMime/Message>
31 32
32using namespace Sink; 33using namespace Sink;
33using namespace Sink::ApplicationDomain; 34using namespace Sink::ApplicationDomain;
@@ -41,6 +42,15 @@ class InterResourceMoveTest : public QObject
41{ 42{
42 Q_OBJECT 43 Q_OBJECT
43 44
45 QByteArray message(const QByteArray &uid, const QString &subject)
46 {
47 KMime::Message m;
48 m.subject(true)->fromUnicodeString(subject, "utf8");
49 m.messageID(true)->setIdentifier(uid);
50 m.assemble();
51 return m.encodedContent();
52 }
53
44private slots: 54private slots:
45 void initTestCase() 55 void initTestCase()
46 { 56 {
@@ -65,24 +75,25 @@ private slots:
65 75
66 void testMove() 76 void testMove()
67 { 77 {
68 Event event("instance1"); 78 QByteArray testuid = "testuid@test.test";
69 event.setProperty("uid", "testuid"); 79 QString subject = "summaryValue";
70 QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); 80 auto mimeMessage = message(testuid, subject);
71 event.setProperty("summary", "summaryValue");
72 VERIFYEXEC(Sink::Store::create<Event>(event));
73 81
82 Mail mail("instance1");
83 mail.setMimeMessage(mimeMessage);
84 VERIFYEXEC(Sink::Store::create<Mail>(mail));
74 85
75 Event createdEvent; 86 Mail createdmail;
76 // Ensure all local data is processed 87 // Ensure all local data is processed
77 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); 88 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1"));
78 { 89 {
79 auto query = Query().resourceFilter("instance1") ; 90 auto query = Query().resourceFilter("instance1") ;
80 auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); 91 auto list = Sink::Store::read<Mail>(query.filter<Mail::MessageId>(testuid));
81 QCOMPARE(list.size(), 1); 92 QCOMPARE(list.size(), 1);
82 createdEvent = list.first(); 93 createdmail = list.first();
83 } 94 }
84 95
85 VERIFYEXEC(Sink::Store::move<Event>(createdEvent, "instance2")); 96 VERIFYEXEC(Sink::Store::move<Mail>(createdmail, "instance2"));
86 97
87 //FIXME we can't guarantee that that the create command arrives at instance2 before the flush command, so we'll just wait for a little bit. 98 //FIXME we can't guarantee that that the create command arrives at instance2 before the flush command, so we'll just wait for a little bit.
88 QTest::qWait(1000); 99 QTest::qWait(1000);
@@ -92,14 +103,18 @@ private slots:
92 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance2")); 103 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance2"));
93 { 104 {
94 auto query = Query().resourceFilter("instance2") ; 105 auto query = Query().resourceFilter("instance2") ;
95 auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); 106 auto list = Sink::Store::read<Mail>(query.filter<Mail::MessageId>(testuid));
96 QCOMPARE(list.size(), 1); 107 QCOMPARE(list.size(), 1);
108 const auto mail = list.first();
109 QVERIFY(!mail.getMimeMessagePath().isEmpty());
110 QCOMPARE(mail.getSubject(), subject);
111 QCOMPARE(mail.getMimeMessage(), mimeMessage);
97 } 112 }
98 113
99 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1")); 114 VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "instance1"));
100 { 115 {
101 auto query = Query().resourceFilter("instance1") ; 116 auto query = Query().resourceFilter("instance1") ;
102 auto list = Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); 117 auto list = Sink::Store::read<Mail>(query.filter<Mail::MessageId>(testuid));
103 QCOMPARE(list.size(), 0); 118 QCOMPARE(list.size(), 0);
104 } 119 }
105 } 120 }