diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-20 14:45:16 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-20 14:45:16 +0200 |
commit | 75d51b5ee87f3c1d34586c34f73c2100d09e1d04 (patch) | |
tree | 9ada52f0b6ccb549c1f80c504cbb7dedb401f1f0 /common | |
parent | 524e405f645edb6231f9b16fafc1f9ca36af8237 (diff) | |
download | sink-75d51b5ee87f3c1d34586c34f73c2100d09e1d04.tar.gz sink-75d51b5ee87f3c1d34586c34f73c2100d09e1d04.zip |
Reread the location if we enable the test mode
Diffstat (limited to 'common')
-rw-r--r-- | common/definitions.cpp | 40 | ||||
-rw-r--r-- | common/definitions.h | 1 | ||||
-rw-r--r-- | 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 @@ | |||
23 | #include <QStandardPaths> | 23 | #include <QStandardPaths> |
24 | #include <QDir> | 24 | #include <QDir> |
25 | 25 | ||
26 | static bool rereadDataLocation = true; | ||
27 | static bool rereadConfigLocation = true; | ||
28 | static bool rereadTemporaryFileLocation = true; | ||
29 | |||
30 | void Sink::clearLocationCache() | ||
31 | { | ||
32 | rereadDataLocation = true; | ||
33 | rereadConfigLocation = true; | ||
34 | rereadTemporaryFileLocation = true; | ||
35 | } | ||
36 | |||
26 | QString Sink::storageLocation() | 37 | QString Sink::storageLocation() |
27 | { | 38 | { |
28 | return dataLocation() + "/storage"; | 39 | return dataLocation() + "/storage"; |
@@ -30,26 +41,37 @@ QString Sink::storageLocation() | |||
30 | 41 | ||
31 | QString Sink::dataLocation() | 42 | QString 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 | ||
37 | QString Sink::configLocation() | 52 | QString 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 | ||
43 | QString Sink::temporaryFileLocation() | 62 | QString 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 | ||
55 | QString Sink::resourceStorageLocation(const QByteArray &resourceInstanceIdentifier) | 77 | 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 @@ | |||
25 | #include <QByteArray> | 25 | #include <QByteArray> |
26 | 26 | ||
27 | namespace Sink { | 27 | namespace Sink { |
28 | void SINK_EXPORT clearLocationCache(); | ||
28 | QString SINK_EXPORT storageLocation(); | 29 | QString SINK_EXPORT storageLocation(); |
29 | QString SINK_EXPORT dataLocation(); | 30 | QString SINK_EXPORT dataLocation(); |
30 | QString SINK_EXPORT configLocation(); | 31 | 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() | |||
81 | void Sink::Test::setTestModeEnabled(bool enabled) | 81 | void 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 { |