[PATCH] If can't write application data to storage, use memory instead.

3 views
Skip to first unread message

Marcelo Lira

unread,
Jun 13, 2012, 10:29:40 AM6/13/12
to snowsh...@googlegroups.com
That's not a normal situation, it only happened in a testing
environment, and this patch is just to avoid the developer being
distracted by meaningless errors. In addition, a warning is issued
stating the problem.

Reviewed-by: ?
---
src/core/DatabaseManager.cpp | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/core/DatabaseManager.cpp b/src/core/DatabaseManager.cpp
index d1f4c47..add3a1e 100644
--- a/src/core/DatabaseManager.cpp
+++ b/src/core/DatabaseManager.cpp
@@ -18,6 +18,7 @@
#include "DatabaseManager.h"
#include "HistoryModel.h"

+#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QString>
#include <QtCore/QStandardPaths>
@@ -45,13 +46,22 @@ DatabaseManager::DatabaseManager()
{
const QString storagePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
QDir storageDir;
+ bool useTemporaryDatabase = false;
if (!storageDir.exists(storagePath))
- storageDir.mkpath(storagePath);
+ useTemporaryDatabase = !storageDir.mkpath(storagePath);

m_database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));

- const QString dataBaseName = storagePath + QLatin1String("/snowshoe.db");
- m_database.setDatabaseName(dataBaseName);
+ if (useTemporaryDatabase) {
+ // This is a very unusual situation, since QStandardPaths::writableLocation returns a valid writable
+ // path. But running as root in a device and trying to write it to the user's data folder does not work.
+ // So for test purposes like these we may store the database on memory.
+ qWarning("[Snowshoe] Can't write to data location, using volatile memory. Bookmarks and history will be lost when the application is closed.");
+ m_database.setDatabaseName(":memory:");
+ } else {
+ const QString dataBaseName = storagePath + QLatin1String("/snowshoe.db");
+ m_database.setDatabaseName(dataBaseName);
+ }

m_bookmarkModel = new BookmarkModel(m_database);

--
1.7.9.5

Alexis Menard

unread,
Jun 13, 2012, 10:42:15 AM6/13/12
to snowsh...@googlegroups.com
But but isn't it prohibited to run such apps in root? So why adding a
workaround of something we should not support.

You can run snowshoe in another user than root.

--
Alexis Menard (darktears)
Software Engineer
openBossa @ INdT - Instituto Nokia de Tecnologia

Marcelo Lira

unread,
Jun 13, 2012, 10:50:17 AM6/13/12
to snowsh...@googlegroups.com
Yep, I ran it as root at first just because, but I stopped doing that.
In any case, the error messages were unrelated to the problem and misleading.
So fearing that something of the sort could happen in other circumstances.

Nevertheless, I think you're right, running it as root was looking for trouble.
I'll dismiss this patch.

>
> --
> Alexis Menard (darktears)
> Software Engineer
> openBossa @ INdT - Instituto Nokia de Tecnologia



--
Marcelo Lira dos Santos
Reply all
Reply to author
Forward
0 new messages