From 75d51b5ee87f3c1d34586c34f73c2100d09e1d04 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 20 May 2017 14:45:16 +0200 Subject: Reread the location if we enable the test mode --- common/definitions.cpp | 40 +++++++++++++++++++++++++++++++--------- common/definitions.h | 1 + common/test.cpp | 1 + 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/common/definitions.cpp b/common/definitions.cpp index 7f4fbbe..17977bc 100644 --- a/common/definitions.cpp +++ b/common/definitions.cpp @@ -23,6 +23,17 @@ #include #include +static bool rereadDataLocation = true; +static bool rereadConfigLocation = true; +static bool rereadTemporaryFileLocation = true; + +void Sink::clearLocationCache() +{ + rereadDataLocation = true; + rereadConfigLocation = true; + rereadTemporaryFileLocation = true; +} + QString Sink::storageLocation() { return dataLocation() + "/storage"; @@ -30,26 +41,37 @@ QString Sink::storageLocation() QString Sink::dataLocation() { - static auto location = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink"; + static QString location; + if (rereadDataLocation) { + location = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink"; + rereadDataLocation = false; + } return location; } QString Sink::configLocation() { - static auto location = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/sink"; + static QString location; + if (rereadConfigLocation) { + location = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/sink"; + rereadConfigLocation = false; + } return location; } QString Sink::temporaryFileLocation() { - static auto path = dataLocation() + "/temporaryFiles"; - static bool initialized = false; - if (!initialized) { - if (QDir{}.mkpath(path)) { - initialized = true; - } + static QString location; + static bool dirCreated = false; + if (rereadTemporaryFileLocation) { + location = dataLocation() + "/temporaryFiles"; + dirCreated = QDir{}.mkpath(location); + rereadTemporaryFileLocation = false; } - return path; + if (!dirCreated && QDir{}.mkpath(location)) { + dirCreated = true; + } + return location; } QString Sink::resourceStorageLocation(const QByteArray &resourceInstanceIdentifier) diff --git a/common/definitions.h b/common/definitions.h index e8cd45e..ce9e794 100644 --- a/common/definitions.h +++ b/common/definitions.h @@ -25,6 +25,7 @@ #include namespace Sink { +void SINK_EXPORT clearLocationCache(); QString SINK_EXPORT storageLocation(); QString SINK_EXPORT dataLocation(); QString SINK_EXPORT configLocation(); diff --git a/common/test.cpp b/common/test.cpp index f9bfa23..237d3bb 100644 --- a/common/test.cpp +++ b/common/test.cpp @@ -81,6 +81,7 @@ void Sink::Test::initTest() void Sink::Test::setTestModeEnabled(bool enabled) { QStandardPaths::setTestModeEnabled(enabled); + Sink::clearLocationCache(); if (enabled) { qputenv("SINK_TESTMODE", "TRUE"); } else { -- cgit v1.2.3