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() :
// This has the down-side that users must restart to
// load changes.
if (!historyFileLocation.exists()) {
QString fileLocation;
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
if (qApp->applicationName() != QLatin1String("konsole")) {
// Check if "kpart"rc has "FileLocation" group; AFAIK
......@@ -82,19 +83,29 @@ HistoryFile::HistoryFile() :
KConfigGroup configGroup = appConfig->group("FileLocation");
if (configGroup.readEntry("scrollbackUseCacheLocation", false)) {
*historyFileLocation() = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
fileLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
} else if (configGroup.readEntry("scrollbackUseSpecifiedLocation", false)) {
const QUrl specifiedUrl = KonsoleSettings::scrollbackUseSpecifiedLocationDirectory();
*historyFileLocation() = specifiedUrl.path();
fileLocation = specifiedUrl.path();
} else {
*historyFileLocation() = QDir::tempPath();
fileLocation = QDir::tempPath();
}
if (!QDir().mkpath(*historyFileLocation())) {
qCWarning(KonsoleDebug)<<"Unable to create scrollback folder "<<*historyFileLocation()
<<" using "<<QDir::homePath();
*historyFileLocation() = QDir::homePath();
// Validate file location
const QFileInfo fi(fileLocation);
if (fileLocation.isEmpty() || !fi.exists() || !fi.isDir() || !fi.isWritable()) {
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 tmpFormat = tmpDir + QLatin1Char('/') + QLatin1String("konsole-XXXXXX.history");
_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