diff options
author | Armin Berres <armin.berres@basyskom.de> | 2011-01-07 12:51:51 +0100 |
---|---|---|
committer | Armin Berres <armin.berres@basyskom.de> | 2011-01-18 15:21:43 +0100 |
commit | ca8539bd7166a1de92ea7cf0bd6c013136bf3a01 (patch) | |
tree | a853d492b1ff0645cdf751c1a3d36f618c737c8e /src/corelib/core/msystemdirectories.cpp | |
parent | badc94d6742f46e68c3f7e5ee7ab81c0632a4db7 (diff) |
Changes: make sure we have a writable cache directory
RevBy: Stanislav Ionascu, Holger Schröder
Details:
So far we were always trying to save our cache files in /var/cache/meegotouch.
This had various side effects on non-linux platforms and also on linux
platforms with missing access rights to this directory.
We now fallback to the cache directory specified by QDesktopServices
if needed.
Diffstat (limited to 'src/corelib/core/msystemdirectories.cpp')
-rw-r--r-- | src/corelib/core/msystemdirectories.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/corelib/core/msystemdirectories.cpp b/src/corelib/core/msystemdirectories.cpp new file mode 100644 index 00000000..6f9f0b2e --- /dev/null +++ b/src/corelib/core/msystemdirectories.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#include "msystemdirectories.h" +#include "qdebug.h" + +#include <QString> +#include <QDesktopServices> +#include <QDir> +#include <QFileInfo> + +#include <cstdlib> + + +QString MSystemDirectories::cacheDirectory() +{ + static QString cacheDir; + if (cacheDir.isEmpty()) { + // first check if we can write to CACHEDIR + cacheDir = CACHEDIR "/"; + QDir().mkpath(cacheDir); + QFileInfo cacheDirInfo(cacheDir); + if (!(cacheDirInfo.isWritable() && cacheDirInfo.isDir())) + { + // now we try a standard cache location + cacheDir = QDesktopServices::storageLocation(QDesktopServices::CacheLocation) + QDir::separator() + QLatin1String("meegotouch") + QDir::separator(); + QDir().mkpath(cacheDir); + cacheDirInfo.setFile(cacheDir); + if (!cacheDirInfo.isWritable() && cacheDirInfo.isDir()) { + qCritical() << "No writable cache directory found. Make sure that either" << QString(CACHEDIR) << "or" << cacheDir << "are writable."; + exit(EXIT_FAILURE); + } + } + } + + return cacheDir; +} |