From 45101d15b0dd9f795572697214998052962e28e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Fri, 1 Aug 2014 11:34:47 +0200 Subject: [PATCH] Store log in ~/.cache by default --- src/libcalamares/utils/CalamaresUtils.cpp | 49 ++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index ec158b6bc..4855698bc 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -29,13 +29,49 @@ #include #include #include +#include #include + +// stdc++ +#include + +using namespace std; + namespace CalamaresUtils { static QDir s_appDataDir( CMAKE_INSTALL_FULL_DATADIR ); +static bool +isWritableDir( const QDir& dir ) +{ + // We log with cerr here because we might be looking for the log dir + QString path = dir.absolutePath(); + if ( !dir.exists() ) + { + if ( !dir.mkpath( "." ) ) + { + cerr << "warning: failed to create " << qPrintable( path ) << endl; + return false; + } + return true; + } + + QFileInfo info( path ); + if ( !info.isDir() ) + { + cerr << "warning: " << qPrintable( path ) << " is not a dir\n"; + return false; + } + if ( !info.isWritable() ) + { + cerr << "warning: " << qPrintable( path ) << " is not writable\n"; + return false; + } + return true; +} + void setAppDataDir( const QDir& dir ) { @@ -61,7 +97,18 @@ systemLibDir() QDir appLogDir() { - return appDataDir(); + QString path = QStandardPaths::writableLocation( QStandardPaths::CacheLocation ); + QDir dir( path ); + if ( isWritableDir( dir ) ) + return dir; + + cerr << "warning: Could not find a standard writable location for log dir, falling back to $HOME\n"; + dir = QDir::home(); + if ( isWritableDir( dir ) ) + return dir; + + cerr << "warning: Found no writable location for log dir, falling back to the temp dir\n"; + return QDir::temp(); }