diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-06 08:18:38 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-02-06 08:38:09 +0100 |
commit | 95854555f038708ddb3fe2e7244deaa57e9a4b8c (patch) | |
tree | 025dd3a2d8dc8d686d02c05175f1582e4b3801ba | |
parent | 9b84aff4b68c3cef3328c85ac12418048b169cee (diff) | |
download | sink-95854555f038708ddb3fe2e7244deaa57e9a4b8c.tar.gz sink-95854555f038708ddb3fe2e7244deaa57e9a4b8c.zip |
Removed all traces of BLOB properties
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 45 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 40 | ||||
-rw-r--r-- | common/domain/propertyregistry.cpp | 9 | ||||
-rw-r--r-- | common/domain/propertyregistry.h | 3 | ||||
-rw-r--r-- | common/propertymapper.cpp | 27 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 59 | ||||
-rw-r--r-- | common/store.cpp | 5 | ||||
-rw-r--r-- | common/store.h | 5 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_list.cpp | 2 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_stat.cpp | 7 |
10 files changed, 5 insertions, 197 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index c1ac7e8..8bb74e3 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -58,12 +58,6 @@ QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDom | |||
58 | return d; | 58 | return d; |
59 | } | 59 | } |
60 | 60 | ||
61 | QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::BLOB &blob) | ||
62 | { | ||
63 | d << blob.value << "external:" << blob.isExternal ; | ||
64 | return d; | ||
65 | } | ||
66 | |||
67 | template <typename DomainType, typename Property> | 61 | template <typename DomainType, typename Property> |
68 | int registerProperty() { | 62 | int registerProperty() { |
69 | Sink::Private::PropertyRegistry::instance().registerProperty<Property>(Sink::ApplicationDomain::getTypeName<DomainType>()); | 63 | Sink::Private::PropertyRegistry::instance().registerProperty<Property>(Sink::ApplicationDomain::getTypeName<DomainType>()); |
@@ -130,13 +124,12 @@ static const int foo = [] { | |||
130 | QMetaType::registerEqualsComparator<Reference>(); | 124 | QMetaType::registerEqualsComparator<Reference>(); |
131 | QMetaType::registerDebugStreamOperator<Reference>(); | 125 | QMetaType::registerDebugStreamOperator<Reference>(); |
132 | QMetaType::registerConverter<Reference, QByteArray>(); | 126 | QMetaType::registerConverter<Reference, QByteArray>(); |
133 | QMetaType::registerDebugStreamOperator<BLOB>(); | ||
134 | QMetaType::registerDebugStreamOperator<Mail::Contact>(); | 127 | QMetaType::registerDebugStreamOperator<Mail::Contact>(); |
135 | qRegisterMetaTypeStreamOperators<Sink::ApplicationDomain::Reference>(); | 128 | qRegisterMetaTypeStreamOperators<Sink::ApplicationDomain::Reference>(); |
136 | return 0; | 129 | return 0; |
137 | }(); | 130 | }(); |
138 | 131 | ||
139 | void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool copyBlobs, bool pruneReferences) | 132 | void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool pruneReferences) |
140 | { | 133 | { |
141 | auto propertiesToCopy = properties; | 134 | auto propertiesToCopy = properties; |
142 | if (properties.isEmpty()) { | 135 | if (properties.isEmpty()) { |
@@ -144,14 +137,7 @@ void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::Applicatio | |||
144 | } | 137 | } |
145 | for (const auto &property : propertiesToCopy) { | 138 | for (const auto &property : propertiesToCopy) { |
146 | const auto value = buffer.getProperty(property); | 139 | const auto value = buffer.getProperty(property); |
147 | if (copyBlobs && value.canConvert<BLOB>()) { | 140 | if (pruneReferences && value.canConvert<Reference>()) { |
148 | const auto oldPath = value.value<BLOB>().value; | ||
149 | const auto newPath = Sink::temporaryFileLocation() + "/" + createUuid(); | ||
150 | if (!QFile::copy(oldPath, newPath)) { | ||
151 | SinkWarning() << "Failed to copy file from: " << oldPath << "to: " << newPath; | ||
152 | } | ||
153 | memoryAdaptor.setProperty(property, QVariant::fromValue(BLOB{newPath})); | ||
154 | } else if (pruneReferences && value.canConvert<Reference>()) { | ||
155 | continue; | 141 | continue; |
156 | } else { | 142 | } else { |
157 | memoryAdaptor.setProperty(property, value); | 143 | memoryAdaptor.setProperty(property, value); |
@@ -245,33 +231,6 @@ void ApplicationDomainType::setProperty(const QByteArray &key, const Application | |||
245 | setProperty(key, QVariant::fromValue(Reference{value.identifier()})); | 231 | setProperty(key, QVariant::fromValue(Reference{value.identifier()})); |
246 | } | 232 | } |
247 | 233 | ||
248 | QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const | ||
249 | { | ||
250 | const auto path = getProperty(key).value<BLOB>().value; | ||
251 | QFile file(path); | ||
252 | if (!file.open(QIODevice::ReadOnly)) { | ||
253 | SinkError() << "Failed to open the file for reading: " << file.errorString() << "Path:" << path << " For property:" << key; | ||
254 | return QByteArray(); | ||
255 | } | ||
256 | return file.readAll(); | ||
257 | } | ||
258 | |||
259 | void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteArray &value) | ||
260 | { | ||
261 | const auto path = Sink::temporaryFileLocation() + "/" + createUuid(); | ||
262 | QFile file(path); | ||
263 | if (!file.open(QIODevice::WriteOnly)) { | ||
264 | SinkError() << "Failed to open the file for writing: " << file.errorString() << path << " For property " << key; | ||
265 | return; | ||
266 | } | ||
267 | if (file.write(value) < 0) { | ||
268 | SinkError() << "Failed to write to file: " << file.errorString() << path << " For property " << key; | ||
269 | } | ||
270 | //Ensure that the file is written to disk immediately | ||
271 | file.close(); | ||
272 | setProperty(key, QVariant::fromValue(BLOB{path})); | ||
273 | } | ||
274 | |||
275 | void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) | 234 | void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) |
276 | { | 235 | { |
277 | *mChangeSet = changeset; | 236 | *mChangeSet = changeset; |
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 8a0daef..b4db54e 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -62,16 +62,6 @@ | |||
62 | void setStatus##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \ | 62 | void setStatus##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \ |
63 | TYPE get##NAME() const { return getProperty(NAME::name).value<TYPE>(); } \ | 63 | TYPE get##NAME() const { return getProperty(NAME::name).value<TYPE>(); } \ |
64 | 64 | ||
65 | #define SINK_BLOB_PROPERTY(NAME, LOWERCASENAME) \ | ||
66 | struct NAME { \ | ||
67 | static constexpr const char *name = #LOWERCASENAME; \ | ||
68 | typedef BLOB Type; \ | ||
69 | }; \ | ||
70 | void set##NAME(const QByteArray &value) { setBlobProperty(NAME::name, value); } \ | ||
71 | void set##NAME##Path(const QString &path) { setProperty(NAME::name, QVariant::fromValue(BLOB{path})); } \ | ||
72 | QByteArray get##NAME() const { return getBlobProperty(NAME::name); } \ | ||
73 | QString get##NAME##Path() const { return getProperty(NAME::name).value<BLOB>().value; } \ | ||
74 | |||
75 | #define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \ | 65 | #define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \ |
76 | struct NAME { \ | 66 | struct NAME { \ |
77 | static constexpr const char *name = #LOWERCASENAME; \ | 67 | static constexpr const char *name = #LOWERCASENAME; \ |
@@ -145,23 +135,6 @@ struct SINK_EXPORT Progress { | |||
145 | /** | 135 | /** |
146 | * Internal type. | 136 | * Internal type. |
147 | * | 137 | * |
148 | * Represents a BLOB property. | ||
149 | */ | ||
150 | struct BLOB { | ||
151 | BLOB() = default; | ||
152 | BLOB(const BLOB &) = default; | ||
153 | BLOB(const QString &id) : value(id) {}; | ||
154 | ~BLOB() = default; | ||
155 | bool operator==(const BLOB &other) const { | ||
156 | return value == other.value && isExternal == other.isExternal; | ||
157 | } | ||
158 | QString value; | ||
159 | bool isExternal = true; | ||
160 | }; | ||
161 | |||
162 | /** | ||
163 | * Internal type. | ||
164 | * | ||
165 | * Represents a reference to another entity in the same resource. | 138 | * Represents a reference to another entity in the same resource. |
166 | */ | 139 | */ |
167 | struct Reference { | 140 | struct Reference { |
@@ -179,7 +152,7 @@ struct Reference { | |||
179 | QByteArray value; | 152 | QByteArray value; |
180 | }; | 153 | }; |
181 | 154 | ||
182 | void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties = QList<QByteArray>(), bool copyBlobs = false, bool pruneReferences = false); | 155 | void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties = QList<QByteArray>(), bool pruneReferences = false); |
183 | 156 | ||
184 | /** | 157 | /** |
185 | * The domain type interface has two purposes: | 158 | * The domain type interface has two purposes: |
@@ -223,7 +196,7 @@ public: | |||
223 | static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList<QByteArray> properties = QList<QByteArray>()) | 196 | static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList<QByteArray> properties = QList<QByteArray>()) |
224 | { | 197 | { |
225 | auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(); | 198 | auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(); |
226 | copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, false, false); | 199 | copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, false); |
227 | //mIdentifier internally still refers to the memory-mapped memory, we need to copy the memory or it will become invalid | 200 | //mIdentifier internally still refers to the memory-mapped memory, we need to copy the memory or it will become invalid |
228 | return QSharedPointer<DomainType>::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); | 201 | return QSharedPointer<DomainType>::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); |
229 | } | 202 | } |
@@ -236,7 +209,7 @@ public: | |||
236 | { | 209 | { |
237 | auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(); | 210 | auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(); |
238 | Q_ASSERT(domainType.mAdaptor); | 211 | Q_ASSERT(domainType.mAdaptor); |
239 | copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true, true); | 212 | copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true); |
240 | return QSharedPointer<DomainType>::create(QByteArray{}, QByteArray{}, 0, memoryAdaptor); | 213 | return QSharedPointer<DomainType>::create(QByteArray{}, QByteArray{}, 0, memoryAdaptor); |
241 | } | 214 | } |
242 | 215 | ||
@@ -287,9 +260,6 @@ public: | |||
287 | */ | 260 | */ |
288 | void setProperty(const QByteArray &key, const ApplicationDomainType &value); | 261 | void setProperty(const QByteArray &key, const ApplicationDomainType &value); |
289 | 262 | ||
290 | QByteArray getBlobProperty(const QByteArray &key) const; | ||
291 | void setBlobProperty(const QByteArray &key, const QByteArray &value); | ||
292 | |||
293 | void setChangedProperties(const QSet<QByteArray> &changeset); | 263 | void setChangedProperties(const QSet<QByteArray> &changeset); |
294 | QByteArrayList changedProperties() const; | 264 | QByteArrayList changedProperties() const; |
295 | QByteArrayList availableProperties() const; | 265 | QByteArrayList availableProperties() const; |
@@ -321,7 +291,6 @@ inline bool operator==(const ApplicationDomainType& lhs, const ApplicationDomain | |||
321 | 291 | ||
322 | SINK_EXPORT QDebug operator<< (QDebug d, const ApplicationDomainType &type); | 292 | SINK_EXPORT QDebug operator<< (QDebug d, const ApplicationDomainType &type); |
323 | SINK_EXPORT QDebug operator<< (QDebug d, const Reference &ref); | 293 | SINK_EXPORT QDebug operator<< (QDebug d, const Reference &ref); |
324 | SINK_EXPORT QDebug operator<< (QDebug d, const BLOB &blob); | ||
325 | 294 | ||
326 | 295 | ||
327 | struct SINK_EXPORT SinkAccount : public ApplicationDomainType { | 296 | struct SINK_EXPORT SinkAccount : public ApplicationDomainType { |
@@ -439,7 +408,6 @@ struct SINK_EXPORT Mail : public Entity { | |||
439 | SINK_PROPERTY(bool, Unread, unread); | 408 | SINK_PROPERTY(bool, Unread, unread); |
440 | SINK_PROPERTY(bool, Important, important); | 409 | SINK_PROPERTY(bool, Important, important); |
441 | SINK_REFERENCE_PROPERTY(Folder, Folder, folder); | 410 | SINK_REFERENCE_PROPERTY(Folder, Folder, folder); |
442 | // SINK_BLOB_PROPERTY(MimeMessage, mimeMessage); | ||
443 | SINK_PROPERTY(QByteArray, MimeMessage, mimeMessage); | 411 | SINK_PROPERTY(QByteArray, MimeMessage, mimeMessage); |
444 | SINK_EXTRACTED_PROPERTY(bool, FullPayloadAvailable, fullPayloadAvailable); | 412 | SINK_EXTRACTED_PROPERTY(bool, FullPayloadAvailable, fullPayloadAvailable); |
445 | SINK_PROPERTY(bool, Draft, draft); | 413 | SINK_PROPERTY(bool, Draft, draft); |
@@ -542,7 +510,6 @@ class SINK_EXPORT TypeImplementation; | |||
542 | #undef SINK_ENTITY | 510 | #undef SINK_ENTITY |
543 | #undef SINK_PROPERTY | 511 | #undef SINK_PROPERTY |
544 | #undef SINK_EXTRACTED_PROPERTY | 512 | #undef SINK_EXTRACTED_PROPERTY |
545 | #undef SINK_BLOB_PROPERTY | ||
546 | #undef SINK_REFERENCE_PROPERTY | 513 | #undef SINK_REFERENCE_PROPERTY |
547 | #undef SINK_INDEX_PROPERTY | 514 | #undef SINK_INDEX_PROPERTY |
548 | 515 | ||
@@ -576,5 +543,4 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact) | |||
576 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Email) | 543 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Email) |
577 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) | 544 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) |
578 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) | 545 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) |
579 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB) | ||
580 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Reference) | 546 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Reference) |
diff --git a/common/domain/propertyregistry.cpp b/common/domain/propertyregistry.cpp index 7b9b61a..755e7b4 100644 --- a/common/domain/propertyregistry.cpp +++ b/common/domain/propertyregistry.cpp | |||
@@ -46,15 +46,6 @@ QVariant parseString<Sink::ApplicationDomain::Reference>(const QString &s) | |||
46 | } | 46 | } |
47 | 47 | ||
48 | template <> | 48 | template <> |
49 | QVariant parseString<Sink::ApplicationDomain::BLOB>(const QString &s) | ||
50 | { | ||
51 | //TODO copy path | ||
52 | // return QVariant::fromValue(Sink::ApplicationDomain::BLOB{s.toLatin1()}); | ||
53 | Q_ASSERT(false); | ||
54 | return QVariant{}; | ||
55 | } | ||
56 | |||
57 | template <> | ||
58 | QVariant parseString<bool>(const QString &s) | 49 | QVariant parseString<bool>(const QString &s) |
59 | { | 50 | { |
60 | if (s == "true") { | 51 | if (s == "true") { |
diff --git a/common/domain/propertyregistry.h b/common/domain/propertyregistry.h index 758c10d..be63989 100644 --- a/common/domain/propertyregistry.h +++ b/common/domain/propertyregistry.h | |||
@@ -43,9 +43,6 @@ template <> | |||
43 | QVariant parseString<Sink::ApplicationDomain::Reference>(const QString &s); | 43 | QVariant parseString<Sink::ApplicationDomain::Reference>(const QString &s); |
44 | 44 | ||
45 | template <> | 45 | template <> |
46 | QVariant parseString<Sink::ApplicationDomain::BLOB>(const QString &s); | ||
47 | |||
48 | template <> | ||
49 | QVariant parseString<bool>(const QString &s); | 46 | QVariant parseString<bool>(const QString &s); |
50 | 47 | ||
51 | template <> | 48 | template <> |
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index dbf93a3..7c313cc 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp | |||
@@ -35,17 +35,6 @@ flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flat | |||
35 | } | 35 | } |
36 | 36 | ||
37 | template <> | 37 | template <> |
38 | flatbuffers::uoffset_t variantToProperty<Sink::ApplicationDomain::BLOB>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | ||
39 | { | ||
40 | if (property.isValid()) { | ||
41 | const auto blob = property.value<Sink::ApplicationDomain::BLOB>(); | ||
42 | auto s = blob.value + (blob.isExternal ? ":ext" : ":int"); | ||
43 | return fbb.CreateString(s.toStdString()).o; | ||
44 | } | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | template <> | ||
49 | flatbuffers::uoffset_t variantToProperty<Sink::ApplicationDomain::Reference>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | 38 | flatbuffers::uoffset_t variantToProperty<Sink::ApplicationDomain::Reference>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) |
50 | { | 39 | { |
51 | if (property.isValid()) { | 40 | if (property.isValid()) { |
@@ -153,22 +142,6 @@ QVariant propertyToVariant<QString>(const flatbuffers::String *property) | |||
153 | } | 142 | } |
154 | 143 | ||
155 | template <> | 144 | template <> |
156 | QVariant propertyToVariant<Sink::ApplicationDomain::BLOB>(const flatbuffers::String *property) | ||
157 | { | ||
158 | if (property) { | ||
159 | // We have to copy the memory, otherwise it would become eventually invalid | ||
160 | auto s = QString::fromStdString(property->str()); | ||
161 | auto ext = s.endsWith(":ext"); | ||
162 | s.chop(4); | ||
163 | |||
164 | auto blob = Sink::ApplicationDomain::BLOB{s}; | ||
165 | blob.isExternal = ext; | ||
166 | return QVariant::fromValue(blob); | ||
167 | } | ||
168 | return QVariant(); | ||
169 | } | ||
170 | |||
171 | template <> | ||
172 | QVariant propertyToVariant<Sink::ApplicationDomain::Reference>(const flatbuffers::String *property) | 145 | QVariant propertyToVariant<Sink::ApplicationDomain::Reference>(const flatbuffers::String *property) |
173 | { | 146 | { |
174 | if (property) { | 147 | if (property) { |
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 5514e31..4ad3eaf 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -96,14 +96,6 @@ class EntityStore::Private { | |||
96 | public: | 96 | public: |
97 | Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore")) | 97 | Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore")) |
98 | { | 98 | { |
99 | static bool initialized = false; | ||
100 | if (!initialized) { | ||
101 | if (QDir{}.mkpath(entityBlobStorageDir())) { | ||
102 | initialized = true; | ||
103 | } else { | ||
104 | SinkWarningCtx(logCtx) << "Failed to create the directory: " << entityBlobStorageDir(); | ||
105 | } | ||
106 | } | ||
107 | } | 99 | } |
108 | 100 | ||
109 | ResourceContext resourceContext; | 101 | ResourceContext resourceContext; |
@@ -158,17 +150,6 @@ public: | |||
158 | auto adaptor = resourceContext.adaptorFactory(type).createAdaptor(buffer.entity(), &typeIndex(type)); | 150 | auto adaptor = resourceContext.adaptorFactory(type).createAdaptor(buffer.entity(), &typeIndex(type)); |
159 | return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor}; | 151 | return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor}; |
160 | } | 152 | } |
161 | |||
162 | QString entityBlobStorageDir() | ||
163 | { | ||
164 | return Sink::resourceStorageLocation(resourceContext.instanceId()) + "/blob"; | ||
165 | } | ||
166 | |||
167 | QString entityBlobStoragePath(const QByteArray &id) | ||
168 | { | ||
169 | return entityBlobStorageDir() +"/"+ id; | ||
170 | } | ||
171 | |||
172 | }; | 153 | }; |
173 | 154 | ||
174 | EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx) | 155 | EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx) |
@@ -205,35 +186,6 @@ bool EntityStore::hasTransaction() const | |||
205 | return d->transaction; | 186 | return d->transaction; |
206 | } | 187 | } |
207 | 188 | ||
208 | void EntityStore::copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision) | ||
209 | { | ||
210 | const auto directory = d->entityBlobStoragePath(entity.identifier()); | ||
211 | |||
212 | for (const auto &property : entity.changedProperties()) { | ||
213 | const auto value = entity.getProperty(property); | ||
214 | if (value.canConvert<ApplicationDomain::BLOB>()) { | ||
215 | const auto blob = value.value<ApplicationDomain::BLOB>(); | ||
216 | //Any blob that is not part of the storage yet has to be moved there. | ||
217 | if (blob.isExternal) { | ||
218 | auto oldPath = blob.value; | ||
219 | auto filePath = directory + QString("_%1%2.blob").arg(QString::number(newRevision)).arg(QString::fromLatin1(property)); | ||
220 | //In case we hit the same revision again due to a rollback. | ||
221 | QFile::remove(filePath); | ||
222 | QFile origFile(oldPath); | ||
223 | if (!origFile.open(QIODevice::ReadWrite)) { | ||
224 | SinkWarningCtx(d->logCtx) << "Failed to open the original file with write rights: " << origFile.errorString(); | ||
225 | } | ||
226 | if (!origFile.rename(filePath)) { | ||
227 | SinkWarningCtx(d->logCtx) << "Failed to move the file from: " << oldPath << " to " << filePath << ". " << origFile.errorString(); | ||
228 | } | ||
229 | origFile.close(); | ||
230 | SinkTraceCtx(d->logCtx) << "Moved blob property: " << property << " from " << oldPath << "to" << filePath; | ||
231 | entity.setProperty(property, QVariant::fromValue(ApplicationDomain::BLOB{filePath})); | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | bool EntityStore::add(const QByteArray &type, ApplicationDomain::ApplicationDomainType entity, bool replayToSource) | 189 | bool EntityStore::add(const QByteArray &type, ApplicationDomain::ApplicationDomainType entity, bool replayToSource) |
238 | { | 190 | { |
239 | if (entity.identifier().isEmpty()) { | 191 | if (entity.identifier().isEmpty()) { |
@@ -248,8 +200,6 @@ bool EntityStore::add(const QByteArray &type, ApplicationDomain::ApplicationDoma | |||
248 | //The maxRevision may have changed meanwhile if the entity created sub-entities | 200 | //The maxRevision may have changed meanwhile if the entity created sub-entities |
249 | const qint64 newRevision = maxRevision() + 1; | 201 | const qint64 newRevision = maxRevision() + 1; |
250 | 202 | ||
251 | copyBlobs(entity, newRevision); | ||
252 | |||
253 | // Add metadata buffer | 203 | // Add metadata buffer |
254 | flatbuffers::FlatBufferBuilder metadataFbb; | 204 | flatbuffers::FlatBufferBuilder metadataFbb; |
255 | auto metadataBuilder = MetadataBuilder(metadataFbb); | 205 | auto metadataBuilder = MetadataBuilder(metadataFbb); |
@@ -317,8 +267,6 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic | |||
317 | 267 | ||
318 | const qint64 newRevision = DataStore::maxRevision(d->transaction) + 1; | 268 | const qint64 newRevision = DataStore::maxRevision(d->transaction) + 1; |
319 | 269 | ||
320 | copyBlobs(newEntity, newRevision); | ||
321 | |||
322 | // Add metadata buffer | 270 | // Add metadata buffer |
323 | flatbuffers::FlatBufferBuilder metadataFbb; | 271 | flatbuffers::FlatBufferBuilder metadataFbb; |
324 | { | 272 | { |
@@ -408,13 +356,6 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) | |||
408 | DataStore::removeRevision(d->transaction, rev); | 356 | DataStore::removeRevision(d->transaction, rev); |
409 | DataStore::mainDatabase(d->transaction, bufferType).remove(key); | 357 | DataStore::mainDatabase(d->transaction, bufferType).remove(key); |
410 | } | 358 | } |
411 | if (isRemoval) { | ||
412 | QDir dir{d->entityBlobStorageDir()}; | ||
413 | const auto infoList = dir.entryInfoList(QStringList{} << QString{uid + "*"}); | ||
414 | for (const auto &fileInfo : infoList) { | ||
415 | QFile::remove(fileInfo.filePath()); | ||
416 | } | ||
417 | } | ||
418 | //Don't cleanup more than specified | 359 | //Don't cleanup more than specified |
419 | if (rev >= revision) { | 360 | if (rev >= revision) { |
420 | return false; | 361 | return false; |
diff --git a/common/store.cpp b/common/store.cpp index a2204fc..edca842 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -71,11 +71,6 @@ QString Store::storageLocation() | |||
71 | return Sink::storageLocation(); | 71 | return Sink::storageLocation(); |
72 | } | 72 | } |
73 | 73 | ||
74 | QString Store::getTemporaryFilePath() | ||
75 | { | ||
76 | return Sink::temporaryFileLocation() + "/" + createUuid(); | ||
77 | } | ||
78 | |||
79 | 74 | ||
80 | template <class DomainType> | 75 | template <class DomainType> |
81 | KAsync::Job<void> queryResource(const QByteArray resourceType, const QByteArray &resourceInstanceIdentifier, const Query &query, typename AggregatingResultEmitter<typename DomainType::Ptr>::Ptr aggregatingEmitter, const Sink::Log::Context &ctx_) | 76 | KAsync::Job<void> queryResource(const QByteArray resourceType, const QByteArray &resourceInstanceIdentifier, const Query &query, typename AggregatingResultEmitter<typename DomainType::Ptr>::Ptr aggregatingEmitter, const Sink::Log::Context &ctx_) |
diff --git a/common/store.h b/common/store.h index 3ad547e..62858c5 100644 --- a/common/store.h +++ b/common/store.h | |||
@@ -43,11 +43,6 @@ namespace Store { | |||
43 | 43 | ||
44 | QString SINK_EXPORT storageLocation(); | 44 | QString SINK_EXPORT storageLocation(); |
45 | 45 | ||
46 | /** | ||
47 | * Returns a unique path for a writable file that can be used to write BLOB properties. | ||
48 | */ | ||
49 | QString SINK_EXPORT getTemporaryFilePath(); | ||
50 | |||
51 | // Must be the same as in ModelResult | 46 | // Must be the same as in ModelResult |
52 | enum Roles | 47 | enum Roles |
53 | { | 48 | { |
diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index e4300f1..8da921f 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp | |||
@@ -73,8 +73,6 @@ QStringList printToList(const Sink::ApplicationDomain::ApplicationDomainType &o, | |||
73 | if (value.isValid()) { | 73 | if (value.isValid()) { |
74 | if (value.canConvert<Sink::ApplicationDomain::Reference>()) { | 74 | if (value.canConvert<Sink::ApplicationDomain::Reference>()) { |
75 | line << compressId(compact, value.toByteArray()); | 75 | line << compressId(compact, value.toByteArray()); |
76 | } else if (value.canConvert<Sink::ApplicationDomain::BLOB>()) { | ||
77 | line << value.value<Sink::ApplicationDomain::BLOB>().value; | ||
78 | } else if (value.canConvert<QString>()) { | 76 | } else if (value.canConvert<QString>()) { |
79 | line << value.toString().mid(0, 75); | 77 | line << value.toString().mid(0, 75); |
80 | } else if (value.canConvert<QByteArray>()) { | 78 | } else if (value.canConvert<QByteArray>()) { |
diff --git a/sinksh/syntax_modules/sink_stat.cpp b/sinksh/syntax_modules/sink_stat.cpp index b4487a8..bb7fc08 100644 --- a/sinksh/syntax_modules/sink_stat.cpp +++ b/sinksh/syntax_modules/sink_stat.cpp | |||
@@ -68,13 +68,6 @@ void statResource(const QString &resource, const State &state) | |||
68 | auto size = diskUsage / 1024; | 68 | auto size = diskUsage / 1024; |
69 | state.printLine(QObject::tr("Actual database file sizes total: %1 [kb]").arg(size), 1); | 69 | state.printLine(QObject::tr("Actual database file sizes total: %1 [kb]").arg(size), 1); |
70 | 70 | ||
71 | QDir dataDir{Sink::resourceStorageLocation(resource.toLatin1()) + "/blob/"}; | ||
72 | Q_ASSERT(dataDir.exists()); | ||
73 | qint64 dataSize = 0; | ||
74 | for (const auto &e : dataDir.entryInfoList(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot)) { | ||
75 | dataSize += e.size(); | ||
76 | } | ||
77 | state.printLine(QObject::tr("Total BLOB size [kb]: %1").arg(dataSize / 1024), 1); | ||
78 | state.printLine(); | 71 | state.printLine(); |
79 | } | 72 | } |
80 | 73 | ||