From 6a3bf46334fc4136da480287898d3f19c88261ee Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 16:15:34 +0200 Subject: Avoid redoing stuff over and over that we can easily avoid. --- common/definitions.cpp | 11 +++++++---- common/storage/entitystore.cpp | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'common') diff --git a/common/definitions.cpp b/common/definitions.cpp index 4bf3da4..7f4fbbe 100644 --- a/common/definitions.cpp +++ b/common/definitions.cpp @@ -30,12 +30,14 @@ QString Sink::storageLocation() QString Sink::dataLocation() { - return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink"; + static auto location = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink"; + return location; } QString Sink::configLocation() { - return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/sink"; + static auto location = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/sink"; + return location; } QString Sink::temporaryFileLocation() @@ -43,8 +45,9 @@ QString Sink::temporaryFileLocation() static auto path = dataLocation() + "/temporaryFiles"; static bool initialized = false; if (!initialized) { - QDir{}.mkpath(path); - initialized = true; + if (QDir{}.mkpath(path)) { + initialized = true; + } } return path; } diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index d2161a6..6ff700e 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -96,9 +96,13 @@ class EntityStore::Private { public: Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore")) { - - if (!QDir().mkpath(entityBlobStorageDir())) { - SinkWarningCtx(logCtx) << "Failed to create the directory: " << entityBlobStorageDir(); + static bool initialized = false; + if (!initialized) { + if (QDir{}.mkpath(entityBlobStorageDir())) { + initialized = true; + } else { + SinkWarningCtx(logCtx) << "Failed to create the directory: " << entityBlobStorageDir(); + } } } -- cgit v1.2.3