D17289: KDevelop/Shell: set dedicated TMPDIR

René J.V. Bertin noreply at phabricator.kde.org
Mon Dec 3 10:21:57 GMT 2018


rjvbb added a comment.


  >   Also, considering that "session" in `Core::initialize` is user-specified and defaults to an empty string, please do not use a 100% deterministic name,
  
  From what I can see the function is only called from main() and the `session` variable will not ever be an empty string in practice. I just tested with a newly created session: even there a new UUID was created before calling Core::initialize().
  
  I can still add the user ID to the dirname just in case `session` is ever empty after all. That's actually useful if TMPDIR isn't set to start with and the directory is created in /tmp .
  
  I just tested QTemporaryDir. It only relieves me from handling the directory creation and deletion because I still have to create the absolute path (and thus prune it): giving just the directory name (instead of a full path) means the directory will be created in the current directory.
  
  So I end up with a slightly cleaner snippet
  
    #if defined(Q_OS_UNIX)
        auto tmpPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
        const QString tmpName(QStringLiteral("/kdevelop-tmp-%1-").arg(getuid()));
        const auto pos = tmpPath.lastIndexOf(tmpName);
        if (pos >= 0) {
            // we must have been started by another KDevelop session,
            // restore the default TempLocation
            tmpPath = tmpPath.left(pos);
        }
        tmpPath += tmpName + session;
        m_tmpLocation = new QTemporaryDir(tmpPath);
        if (m_tmpLocation->isValid()) {
            qputenv("TMPDIR", tmpPath.toLatin1());
            qCDebug(SHELL) << "temp. directory:" << m_tmpLocation->path();
        }
    #endif
  
  and still don't have a deterministic name because QTemporaryDir will always add something random to the name even if you don't include an "XXXXXX" pattern in the template. From the docs:
  
    If the templatePath ends with XXXXXX it will be used as the dynamic portion of the directory name, otherwise it will be appended.
  
  and this is obligatory on Unix as `mkdtemp()` is used underneath. So the snippet above is actually broken, the temp dir is not at `tmpLocation`.
  Come to think of it, the directory is also not emptied on creation as I want it to be; the class guarantees it never reuses an existing directory.

REPOSITORY
  R32 KDevelop

REVISION DETAIL
  https://phabricator.kde.org/D17289

To: rjvbb, #kdevelop, kfunk
Cc: pino, kfunk, kdevelop-devel, glebaccon, hase, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20181203/cacb7846/attachment.html>


More information about the KDevelop-devel mailing list