Merge lp:~marcustomlinson/unity-scopes-shell/lp-1583055 into lp:unity-scopes-shell

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 317
Merged at revision: 323
Proposed branch: lp:~marcustomlinson/unity-scopes-shell/lp-1583055
Merge into: lp:unity-scopes-shell
Diff against target: 81 lines (+13/-10)
2 files modified
src/Unity/settingsmodel.cpp (+12/-9)
src/Unity/settingsmodel.h (+1/-1)
To merge this branch: bzr merge lp:~marcustomlinson/unity-scopes-shell/lp-1583055
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+295161@code.launchpad.net

Commit message

Only create an empty settings file when attempting to write to one

To post a comment you must log in.
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

I have tested this on the phone. If you'd like to confirm, here's a build: https://code.launchpad.net/~unity-api-team/+archive/ubuntu/dev-build-4

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good, thanks Markus!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Unity/settingsmodel.cpp'
--- src/Unity/settingsmodel.cpp 2016-04-19 08:04:55 +0000
+++ src/Unity/settingsmodel.cpp 2016-05-19 07:18:35 +0000
@@ -86,12 +86,11 @@
8686
87 try87 try
88 {88 {
89 tryLoadSettings();89 tryLoadSettings(true);
90 }90 }
91 catch(const unity::FileException& e)91 catch(const unity::FileException&)
92 {92 {
93 // Something has gone wrong, at this point we'll just have to continue with a null m_settings.93 // No settings file found, at this point we'll just have to continue with a null m_settings.
94 qWarning() << "SettingsModel::SettingsModel: Failed to read settings file:" << e.what();
95 }94 }
9695
97 for (const auto &it : settingsDefinitions.toList())96 for (const auto &it : settingsDefinitions.toList())
@@ -179,7 +178,7 @@
179 {178 {
180 try179 try
181 {180 {
182 tryLoadSettings();181 tryLoadSettings(true);
183 switch (data->variantType)182 switch (data->variantType)
184 {183 {
185 case QVariant::Bool:184 case QVariant::Bool:
@@ -269,7 +268,7 @@
269 QVariant result;268 QVariant result;
270 try269 try
271 {270 {
272 tryLoadSettings();271 tryLoadSettings(true);
273 switch (data->variantType)272 switch (data->variantType)
274 {273 {
275 case QVariant::Bool:274 case QVariant::Bool:
@@ -486,7 +485,7 @@
486 {485 {
487 try486 try
488 {487 {
489 tryLoadSettings();488 tryLoadSettings(false);
490 switch (value.type())489 switch (value.type())
491 {490 {
492 case QVariant::Bool:491 case QVariant::Bool:
@@ -526,15 +525,19 @@
526 }525 }
527}526}
528527
529void SettingsModel::tryLoadSettings() const528void SettingsModel::tryLoadSettings(bool read_only) const
530{529{
531 if (!m_settings)530 if (!m_settings)
532 {531 {
533 QFileInfo checkFile(m_settings_path);532 QFileInfo checkFile(m_settings_path);
534 if (!checkFile.exists() || !checkFile.isFile())533 if (!checkFile.exists() || !checkFile.isFile())
535 {534 {
535 if (read_only)
536 {
537 throw unity::FileException("Could not locate a settings file at: " + m_settings_path.toStdString(), -1);
538 }
536 // Config file does not exist, so we create an empty one.539 // Config file does not exist, so we create an empty one.
537 if (!QFile(m_settings_path).open(QFile::WriteOnly))540 else if (!QFile(m_settings_path).open(QFile::WriteOnly))
538 {541 {
539 throw unity::FileException("Could not create an empty settings file at: " + m_settings_path.toStdString(), -1);542 throw unity::FileException("Could not create an empty settings file at: " + m_settings_path.toStdString(), -1);
540 }543 }
541544
=== modified file 'src/Unity/settingsmodel.h'
--- src/Unity/settingsmodel.h 2016-04-18 16:18:20 +0000
+++ src/Unity/settingsmodel.h 2016-05-19 07:18:35 +0000
@@ -91,7 +91,7 @@
91 void settings_timeout();91 void settings_timeout();
9292
93private:93private:
94 void tryLoadSettings() const;94 void tryLoadSettings(bool read_only) const;
9595
96protected:96protected:
97 mutable QMutex m_mutex;97 mutable QMutex m_mutex;

Subscribers

People subscribed via source and target branches

to all changes: