make sure that the temp folder exists

This commit is contained in:
Patrick von Reth 2014-09-16 18:25:59 +02:00
parent 0d46672737
commit 640a985ecb
2 changed files with 11 additions and 3 deletions

View File

@ -53,14 +53,17 @@ public:
static QFile *s_file = NULL; static QFile *s_file = NULL;
if (!s_out) { if (!s_out) {
QString name = QString("%1/libsnore/%2-log.txt").arg(QDir::tempPath(), qApp->applicationName().isEmpty() ? QString::number(qApp->applicationPid()) : qApp->applicationName()); QString name = QString("%1/libsnore/%2-log.txt").arg(QDir::tempPath(), qApp->applicationName().isEmpty() ? QString::number(qApp->applicationPid()) : qApp->applicationName());
if (!qgetenv("LIBSNORE_LOGFILE").isNull()) { if (!qgetenv("LIBSNORE_LOGFILE").isNull()) {
name = QString(qgetenv("LIBSNORE_LOGFILE")); name = QString(qgetenv("LIBSNORE_LOGFILE"));
} else {
QDir::temp().mkpath("libsnore");
} }
std::cout << "Started logging to " << name.toUtf8().constData() << std::endl; std::cout << "Started logging to " << name.toUtf8().constData() << std::endl;
s_file = new QFile(name); s_file = new QFile(name);
s_file->open(QFile::WriteOnly); if(!s_file->open(QFile::WriteOnly)) {
qFatal("Failed to open log file %s", qPrintable(name));
}
s_out = new QTextStream(s_file); s_out = new QTextStream(s_file);
} }
return *s_out; return *s_out;

View File

@ -87,7 +87,12 @@ QString SnoreCorePrivate::tempPath()
static QTemporaryDir dir; static QTemporaryDir dir;
return dir.path(); return dir.path();
#else #else
return QString("%1/%2").arg(QDir::tempPath(), "libsnore"); static QString dir;
if(dir.isEmpty()) {
dir = QString("%1/%2").arg(QDir::tempPath(), "libsnore");
QDir::temp().mkpath("libsnore");
}
return dir;
#endif #endif
} }