diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2017-01-19 16:44:22 +0100 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2017-01-20 12:17:10 +0000 |
commit | c6f90e575e2e261f7fa50f951b6fc1824ae5c12f (patch) | |
tree | 7f3564ad1491a5f40e64bcee89d70b884409885f /src/plugins/debugger | |
parent | e6017c40fca059b27e449f0605f4d79b78de0ff3 (diff) | |
download | qt-creator-c6f90e575e2e261f7fa50f951b6fc1824ae5c12f.tar.gz |
Utils: Introduce a TemporaryDirectory and TemporaryFile class
Both wrap the corresponding Qt class, but make sure all temporary files
or directories are created inside a "master temporary directory".
Change-Id: I55461be507c828c965224c02863ea5ed9bbf9498
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/plugins/debugger')
-rw-r--r-- | src/plugins/debugger/debuggerplugin.cpp | 2 | ||||
-rw-r--r-- | src/plugins/debugger/gdb/coregdbadapter.cpp | 10 | ||||
-rw-r--r-- | src/plugins/debugger/gdb/gdbengine.cpp | 6 | ||||
-rw-r--r-- | src/plugins/debugger/imageviewer.cpp | 10 | ||||
-rw-r--r-- | src/plugins/debugger/loadcoredialog.cpp | 4 | ||||
-rw-r--r-- | src/plugins/debugger/outputcollector.cpp | 4 | ||||
-rw-r--r-- | src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp | 5 |
7 files changed, 20 insertions, 21 deletions
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index a63fdbdc4a..e904a35d03 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -2743,7 +2743,7 @@ void DebuggerPluginPrivate::updateDebugWithoutDeployMenu() void DebuggerPluginPrivate::dumpLog() { QString fileName = QFileDialog::getSaveFileName(ICore::mainWindow(), - tr("Save Debugger Log"), QDir::tempPath()); + tr("Save Debugger Log"), Utils::TemporaryDirectory::masterDirectoryPath()); if (fileName.isEmpty()) return; FileSaver saver(fileName); diff --git a/src/plugins/debugger/gdb/coregdbadapter.cpp b/src/plugins/debugger/gdb/coregdbadapter.cpp index df213dd59d..f21e3dbd67 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.cpp +++ b/src/plugins/debugger/gdb/coregdbadapter.cpp @@ -34,9 +34,10 @@ #include <utils/fileutils.h> #include <utils/qtcassert.h> #include <utils/synchronousprocess.h> +#include <utils/temporarydirectory.h> +#include <utils/temporaryfile.h> #include <QDir> -#include <QTemporaryFile> using namespace Utils; using namespace ProjectExplorer; @@ -277,8 +278,7 @@ void GdbCoreEngine::shutdownEngine() static QString tempCoreFilename() { - QString pattern = QDir::tempPath() + QLatin1String("/tmpcore-XXXXXX"); - QTemporaryFile tmp(pattern); + Utils::TemporaryFile tmp("tmpcore-XXXXXX"); tmp.open(); return tmp.fileName(); } @@ -292,7 +292,7 @@ void GdbCoreEngine::unpackCoreIfNeeded() showMessage(msg.arg(m_tempCoreName)); arguments << QLatin1String("-o") << m_tempCoreName << QLatin1String("-x") << m_coreName; m_coreUnpackProcess = new QProcess(this); - m_coreUnpackProcess->setWorkingDirectory(QDir::tempPath()); + m_coreUnpackProcess->setWorkingDirectory(Utils::TemporaryDirectory::masterDirectoryPath()); m_coreUnpackProcess->start(QLatin1String("lzop"), arguments); connect(m_coreUnpackProcess, static_cast<void (QProcess::*)(int)>(&QProcess::finished), this, &GdbCoreEngine::continueSetupEngine); @@ -303,7 +303,7 @@ void GdbCoreEngine::unpackCoreIfNeeded() m_tempCoreFile.open(QFile::WriteOnly); arguments << QLatin1String("-c") << QLatin1String("-d") << m_coreName; m_coreUnpackProcess = new QProcess(this); - m_coreUnpackProcess->setWorkingDirectory(QDir::tempPath()); + m_coreUnpackProcess->setWorkingDirectory(Utils::TemporaryDirectory::masterDirectoryPath()); m_coreUnpackProcess->start(QLatin1String("gzip"), arguments); connect(m_coreUnpackProcess, &QProcess::readyRead, this, &GdbCoreEngine::writeCoreChunk); connect(m_coreUnpackProcess, static_cast<void (QProcess::*)(int)>(&QProcess::finished), diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index e5da59b034..4ee01857f0 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -71,13 +71,13 @@ #include <utils/qtcassert.h> #include <utils/qtcprocess.h> #include <utils/savedaction.h> +#include <utils/temporaryfile.h> #include <QBuffer> #include <QDirIterator> #include <QMessageBox> #include <QProcess> #include <QPushButton> -#include <QTemporaryFile> #include <QJsonArray> using namespace Core; @@ -2999,7 +2999,7 @@ static void handleShowModuleSymbols(const DebuggerResponse &response, void GdbEngine::requestModuleSymbols(const QString &modulePath) { - QTemporaryFile tf(QDir::tempPath() + "/gdbsymbols"); + Utils::TemporaryFile tf("gdbsymbols"); if (!tf.open()) return; QString fileName = tf.fileName(); @@ -3351,7 +3351,7 @@ void GdbEngine::handleThreadNames(const DebuggerResponse &response) void GdbEngine::createSnapshot() { QString fileName; - QTemporaryFile tf(QDir::tempPath() + "/gdbsnapshot"); + Utils::TemporaryFile tf("gdbsnapshot"); if (tf.open()) { fileName = tf.fileName(); tf.close(); diff --git a/src/plugins/debugger/imageviewer.cpp b/src/plugins/debugger/imageviewer.cpp index 1b486ceccf..02deecfadf 100644 --- a/src/plugins/debugger/imageviewer.cpp +++ b/src/plugins/debugger/imageviewer.cpp @@ -30,6 +30,8 @@ #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/idocument.h> +#include <utils/temporaryfile.h> + #include <QAction> #include <QLabel> #include <QMenu> @@ -41,7 +43,6 @@ #include <QApplication> #include <QPainter> #include <QDir> -#include <QTemporaryFile> // Widget showing the image in a 1-pixel frame with context menu. class ImageWidget : public QWidget @@ -131,12 +132,9 @@ void ImageViewer::clicked(const QString &message) // Open Qt Creator's image viewer static void openImageViewer(const QImage &image) { - QString fileName = QDir::tempPath(); - if (!fileName.endsWith(QLatin1Char('/'))) - fileName += QLatin1Char('/'); - fileName += QLatin1String("qtcreatorXXXXXX.png"); + QString fileName; { - QTemporaryFile temporaryFile(fileName); + Utils::TemporaryFile temporaryFile("qtcreatorXXXXXX.png"); temporaryFile.setAutoRemove(false); image.save(&temporaryFile); fileName = temporaryFile.fileName(); diff --git a/src/plugins/debugger/loadcoredialog.cpp b/src/plugins/debugger/loadcoredialog.cpp index 4241a50889..d0e8d87636 100644 --- a/src/plugins/debugger/loadcoredialog.cpp +++ b/src/plugins/debugger/loadcoredialog.cpp @@ -35,12 +35,12 @@ #include <ssh/sftpfilesystemmodel.h> #include <utils/pathchooser.h> #include <utils/qtcassert.h> +#include <utils/temporaryfile.h> #include <QCheckBox> #include <QDebug> #include <QDir> #include <QRegExp> -#include <QTemporaryFile> #include <QDialogButtonBox> #include <QFormLayout> @@ -184,7 +184,7 @@ void SelectRemoteFileDialog::selectFile() this, &SelectRemoteFileDialog::handleSftpOperationFinished); { - QTemporaryFile localFile(QDir::tempPath() + QLatin1String("/remotecore-XXXXXX")); + Utils::TemporaryFile localFile("remotecore-XXXXXX"); localFile.open(); m_localFile = localFile.fileName(); } diff --git a/src/plugins/debugger/outputcollector.cpp b/src/plugins/debugger/outputcollector.cpp index 4fad571c61..da93e631b9 100644 --- a/src/plugins/debugger/outputcollector.cpp +++ b/src/plugins/debugger/outputcollector.cpp @@ -34,9 +34,9 @@ #include <stdlib.h> #else +#include <utils/temporaryfile.h> #include <QSocketNotifier> -#include <QTemporaryFile> #include <QVarLengthArray> #include <sys/ioctl.h> @@ -85,7 +85,7 @@ bool OutputCollector::listen() QByteArray codedServerPath; forever { { - QTemporaryFile tf; + Utils::TemporaryFile tf("outputcollector"); if (!tf.open()) { m_errorString = tr("Cannot create temporary file: %1").arg(tf.errorString()); m_serverPath.clear(); diff --git a/src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp b/src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp index 9abfca5341..c5ad414633 100644 --- a/src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp +++ b/src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp @@ -30,6 +30,7 @@ #include <utils/pathchooser.h> #include <utils/checkablemessagebox.h> +#include <utils/temporarydirectory.h> #include "symbolpathsdialog.h" @@ -139,7 +140,7 @@ CdbSymbolPathListEditor::CdbSymbolPathListEditor(QWidget *parent) : bool CdbSymbolPathListEditor::promptCacheDirectory(QWidget *parent, QString *cacheDirectory) { CacheDirectoryDialog dialog(parent); - dialog.setPath(QDir::tempPath() + QDir::separator() + QLatin1String("symbolcache")); + dialog.setPath(Utils::TemporaryDirectory::masterDirectoryPath() + "/symbolcache"); if (dialog.exec() != QDialog::Accepted) return false; *cacheDirectory = dialog.path(); @@ -165,7 +166,7 @@ void CdbSymbolPathListEditor::setupSymbolPaths() if (path.isEmpty() && indexOfSymbolCache != -1) path = currentPaths.at(indexOfSymbolCache); if (path.isEmpty()) - path = QDir::tempPath() + QDir::separator() + QLatin1String("symbolcache"); + path = Utils::TemporaryDirectory::masterDirectoryPath() + "/symbolcache"; bool useSymbolServer = true; bool useSymbolCache = true; |