Commit a9f3f4f6 authored by Kurt Hindenburg's avatar Kurt Hindenburg
Browse files

Validate scrollback destination folder for unlimited scrollback option

Perform some basic checks on the folder where the scrollback files
will be stored when unlimited scrollback is selected.

(cherry picked from commit 9788f0e5)
parent 0f16d66c
...@@ -70,6 +70,7 @@ HistoryFile::HistoryFile() : ...@@ -70,6 +70,7 @@ HistoryFile::HistoryFile() :
// This has the down-side that users must restart to // This has the down-side that users must restart to
// load changes. // load changes.
if (!historyFileLocation.exists()) { if (!historyFileLocation.exists()) {
QString fileLocation;
KSharedConfigPtr appConfig = KSharedConfig::openConfig(); KSharedConfigPtr appConfig = KSharedConfig::openConfig();
if (qApp->applicationName() != QLatin1String("konsole")) { if (qApp->applicationName() != QLatin1String("konsole")) {
// Check if "kpart"rc has "FileLocation" group; AFAIK // Check if "kpart"rc has "FileLocation" group; AFAIK
...@@ -82,19 +83,29 @@ HistoryFile::HistoryFile() : ...@@ -82,19 +83,29 @@ HistoryFile::HistoryFile() :
KConfigGroup configGroup = appConfig->group("FileLocation"); KConfigGroup configGroup = appConfig->group("FileLocation");
if (configGroup.readEntry("scrollbackUseCacheLocation", false)) { if (configGroup.readEntry("scrollbackUseCacheLocation", false)) {
*historyFileLocation() = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); fileLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
} else if (configGroup.readEntry("scrollbackUseSpecifiedLocation", false)) { } else if (configGroup.readEntry("scrollbackUseSpecifiedLocation", false)) {
const QUrl specifiedUrl = KonsoleSettings::scrollbackUseSpecifiedLocationDirectory(); const QUrl specifiedUrl = KonsoleSettings::scrollbackUseSpecifiedLocationDirectory();
*historyFileLocation() = specifiedUrl.path(); fileLocation = specifiedUrl.path();
} else { } else {
*historyFileLocation() = QDir::tempPath(); fileLocation = QDir::tempPath();
} }
if (!QDir().mkpath(*historyFileLocation())) { // Validate file location
qCWarning(KonsoleDebug)<<"Unable to create scrollback folder "<<*historyFileLocation() const QFileInfo fi(fileLocation);
<<" using "<<QDir::homePath(); if (fileLocation.isEmpty() || !fi.exists() || !fi.isDir() || !fi.isWritable()) {
*historyFileLocation() = QDir::homePath(); qCWarning(KonsoleDebug)<<"Invalid scrollback folder "<<fileLocation<<"; using " << QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
// Per Qt docs, this path is never empty; not sure if that
// means it always exists.
fileLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
const QFileInfo fi2(fileLocation);
if (!fi2.exists()) {
if (!QDir().mkpath(fileLocation)) {
qCWarning(KonsoleDebug)<<"Unable to create scrollback folder "<<fileLocation;
} }
} }
}
*historyFileLocation() = fileLocation;
}
const QString tmpDir = *historyFileLocation(); const QString tmpDir = *historyFileLocation();
const QString tmpFormat = tmpDir + QLatin1Char('/') + QLatin1String("konsole-XXXXXX.history"); const QString tmpFormat = tmpDir + QLatin1Char('/') + QLatin1String("konsole-XXXXXX.history");
_tmpFile.setFileTemplate(tmpFormat); _tmpFile.setFileTemplate(tmpFormat);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment