Index: kdevplatform/shell/core.h =================================================================== --- kdevplatform/shell/core.h +++ kdevplatform/shell/core.h @@ -24,6 +24,7 @@ #include "shellexport.h" #include +class QProcessEnvironment; class KAboutData; namespace KDevelop { @@ -90,6 +91,14 @@ KAboutData aboutData() const override; + /** + * Returns the our current environment with TMPDIR reset to + * its original value, in a form suitable to defined the + * environment for child processes without alterning our own. + * \see QProcessEnvironment::systemEnvironment() + */ + void systemEnvironment(QProcessEnvironment& env) const; + /// The following methods may only be used within the shell. UiController *uiControllerInternal(); Index: kdevplatform/shell/core.cpp =================================================================== --- kdevplatform/shell/core.cpp +++ kdevplatform/shell/core.cpp @@ -21,6 +21,7 @@ #include "core_p.h" #include +#include #include @@ -130,6 +131,30 @@ m_mode=mode; qCDebug(SHELL) << "Creating controllers"; +#if defined(Q_OS_UNIX) + auto tmpLocation = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + const QString tmpName(QStringLiteral("/kdevelop-tmp-%1-").arg(getuid())); + const auto pos = tmpLocation.lastIndexOf(tmpName); + if (pos >= 0) { + // we must have been started by another KDevelop session, + // restore the default TempLocation + tmpLocation = tmpLocation.left(pos); + } + tmpLocation += tmpName + session; + m_tmpDir = new QDir(tmpLocation); + if (m_tmpDir->exists()) { + qCDebug(SHELL) << "Removing existing session temp dir" << tmpLocation; + m_tmpDir->removeRecursively(); + } + m_tmpDir->mkpath(tmpLocation); + if (m_tmpDir->exists()) { + const auto origTmpDir = qgetenv("TMPDIR"); + if (!origTmpDir.isEmpty()) { + m_originalTmpDir = QString::fromUtf8(origTmpDir); + } + qputenv("TMPDIR", tmpLocation.toLatin1()); + } +#endif if( !sessionController ) { @@ -313,6 +338,11 @@ delete testController.data(); delete runtimeController.data(); + if (m_tmpDir->exists()) { + m_tmpDir->removeRecursively(); + delete m_tmpDir; + } + selectionController.clear(); projectController.clear(); languageController.clear(); @@ -447,6 +477,16 @@ return d->m_aboutData; } +void Core::systemEnvironment(QProcessEnvironment& env) const +{ + env = QProcessEnvironment::systemEnvironment(); + if (!d->m_originalTmpDir.isEmpty()) { + // restore the original TMPDIR value + env.remove(QStringLiteral("TMPDIR")); + env.insert(QStringLiteral("TMPDIR" ), d->m_originalTmpDir); + } +} + IUiController *Core::uiController() { return d->uiController.data(); Index: kdevplatform/shell/core_p.h =================================================================== --- kdevplatform/shell/core_p.h +++ kdevplatform/shell/core_p.h @@ -26,6 +26,7 @@ #include #include +class QDir; namespace KDevelop { @@ -74,6 +75,8 @@ bool m_cleanedUp; bool m_shuttingDown; Core::Setup m_mode; + QString m_originalTmpDir; + QDir* m_tmpDir = nullptr; }; }