[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [konsole] src: Validate initial working directory Profile entry
From:       Kurt Hindenburg <kurt.hindenburg () gmail ! com>
Date:       2016-10-08 20:32:15
Message-ID: E1bsyI3-0001Vo-MR () code ! kde ! org
[Download RAW message or body]

Git commit 6e2d3f4e7e952a342ed91bf93d4487bd51a331ea by Kurt Hindenburg.
Committed on 08/10/2016 at 20:32.
Pushed by hindenburg into branch 'master'.

Validate initial working directory Profile entry

Verify the Profile's initial working directory exists and is a dir

This applies to KonsolePart as well as Konsole

M  +1    -0    src/Part.cpp
M  +16   -1    src/Session.cpp
M  +2    -0    src/Session.h

http://commits.kde.org/konsole/6e2d3f4e7e952a342ed91bf93d4487bd51a331ea

diff --git a/src/Part.cpp b/src/Part.cpp
index 07f8cf7..7968176 100644
--- a/src/Part.cpp
+++ b/src/Part.cpp
@@ -139,6 +139,7 @@ void Part::showShellInDir(const QString& dir)
     if (activeSession()->isRunning())
         return;
 
+    // All other checking is done in setInitialWorkingDirectory()
     if (!dir.isEmpty())
         activeSession()->setInitialWorkingDirectory(dir);
 
diff --git a/src/Session.cpp b/src/Session.cpp
index 68f0ffc..302bddc 100644
--- a/src/Session.cpp
+++ b/src/Session.cpp
@@ -264,7 +264,7 @@ void Session::setArguments(const QStringList& arguments)
 
 void Session::setInitialWorkingDirectory(const QString& dir)
 {
-    _initialWorkingDir = KShell::tildeExpand(ShellCommand::expand(dir));
+    _initialWorkingDir = validDirectory(KShell::tildeExpand(ShellCommand::expand(dir)));
 }
 
 QString Session::currentWorkingDirectory()
@@ -1550,6 +1550,21 @@ void Session::restoreSession(KConfigGroup& group)
     if (!value.isEmpty()) setCodec(value.toUtf8());
 }
 
+QString Session::validDirectory(const QString& dir) const
+{
+    QString validDir = dir;
+    if (validDir.isEmpty()) {
+        validDir = QDir::currentPath();
+    }
+
+    const QFileInfo fi(validDir);
+    if (!fi.exists() || !fi.isDir()) {
+        validDir = QDir::homePath();
+    }
+
+    return validDir;
+}
+
 SessionGroup::SessionGroup(QObject* parent)
     : QObject(parent), _masterMode(0)
 {
diff --git a/src/Session.h b/src/Session.h
index 397b515..30248b3 100644
--- a/src/Session.h
+++ b/src/Session.h
@@ -730,6 +730,8 @@ private:
     bool updateForegroundProcessInfo();
     void updateWorkingDirectory();
 
+    QString validDirectory(const QString& directory) const;
+
     QUuid            _uniqueIdentifier; // SHELL_SESSION_ID
 
     Pty*          _shellProcess;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic