summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/definitions.cpp40
-rw-r--r--common/definitions.h1
-rw-r--r--common/test.cpp1
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 @@
23#include <QStandardPaths> 23#include <QStandardPaths>
24#include <QDir> 24#include <QDir>
25 25
26static bool rereadDataLocation = true;
27static bool rereadConfigLocation = true;
28static bool rereadTemporaryFileLocation = true;
29
30void Sink::clearLocationCache()
31{
32 rereadDataLocation = true;
33 rereadConfigLocation = true;
34 rereadTemporaryFileLocation = true;
35}
36
26QString Sink::storageLocation() 37QString Sink::storageLocation()
27{ 38{
28 return dataLocation() + "/storage"; 39 return dataLocation() + "/storage";
@@ -30,26 +41,37 @@ QString Sink::storageLocation()
30 41
31QString Sink::dataLocation() 42QString Sink::dataLocation()
32{ 43{
33 static auto location = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink"; 44 static QString location;
45 if (rereadDataLocation) {
46 location = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink";
47 rereadDataLocation = false;
48 }
34 return location; 49 return location;
35} 50}
36 51
37QString Sink::configLocation() 52QString Sink::configLocation()
38{ 53{
39 static auto location = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/sink"; 54 static QString location;
55 if (rereadConfigLocation) {
56 location = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/sink";
57 rereadConfigLocation = false;
58 }
40 return location; 59 return location;
41} 60}
42 61
43QString Sink::temporaryFileLocation() 62QString Sink::temporaryFileLocation()
44{ 63{
45 static auto path = dataLocation() + "/temporaryFiles"; 64 static QString location;
46 static bool initialized = false; 65 static bool dirCreated = false;
47 if (!initialized) { 66 if (rereadTemporaryFileLocation) {
48 if (QDir{}.mkpath(path)) { 67 location = dataLocation() + "/temporaryFiles";
49 initialized = true; 68 dirCreated = QDir{}.mkpath(location);
50 } 69 rereadTemporaryFileLocation = false;
51 } 70 }
52 return path; 71 if (!dirCreated && QDir{}.mkpath(location)) {
72 dirCreated = true;
73 }
74 return location;
53} 75}
54 76
55QString Sink::resourceStorageLocation(const QByteArray &resourceInstanceIdentifier) 77QString 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 @@
25#include <QByteArray> 25#include <QByteArray>
26 26
27namespace Sink { 27namespace Sink {
28void SINK_EXPORT clearLocationCache();
28QString SINK_EXPORT storageLocation(); 29QString SINK_EXPORT storageLocation();
29QString SINK_EXPORT dataLocation(); 30QString SINK_EXPORT dataLocation();
30QString SINK_EXPORT configLocation(); 31QString 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()
81void Sink::Test::setTestModeEnabled(bool enabled) 81void Sink::Test::setTestModeEnabled(bool enabled)
82{ 82{
83 QStandardPaths::setTestModeEnabled(enabled); 83 QStandardPaths::setTestModeEnabled(enabled);
84 Sink::clearLocationCache();
84 if (enabled) { 85 if (enabled) {
85 qputenv("SINK_TESTMODE", "TRUE"); 86 qputenv("SINK_TESTMODE", "TRUE");
86 } else { 87 } else {