aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/temporarydirectory.cpp
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2017-01-19 16:44:22 +0100
committerTim Jenssen <tim.jenssen@qt.io>2017-01-20 12:17:10 +0000
commitc6f90e575e2e261f7fa50f951b6fc1824ae5c12f (patch)
tree7f3564ad1491a5f40e64bcee89d70b884409885f /src/libs/utils/temporarydirectory.cpp
parente6017c40fca059b27e449f0605f4d79b78de0ff3 (diff)
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/libs/utils/temporarydirectory.cpp')
-rw-r--r--src/libs/utils/temporarydirectory.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/libs/utils/temporarydirectory.cpp b/src/libs/utils/temporarydirectory.cpp
new file mode 100644
index 00000000000..c0d0c15cb1b
--- /dev/null
+++ b/src/libs/utils/temporarydirectory.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "temporarydirectory.h"
+
+#include "qtcassert.h"
+
+#include <memory>
+
+namespace Utils {
+
+static std::unique_ptr<QTemporaryDir> m_masterTemporaryDir;
+
+TemporaryDirectory::TemporaryDirectory(const QString &pattern) :
+ QTemporaryDir(m_masterTemporaryDir->path() + '/' + pattern)
+{
+ QTC_CHECK(!QFileInfo(pattern).isAbsolute());
+}
+
+QTemporaryDir *TemporaryDirectory::masterTemporaryDirectory()
+{
+ return m_masterTemporaryDir.get();
+}
+
+void TemporaryDirectory::setMasterTemporaryDirectory(const QString &pattern)
+{
+ m_masterTemporaryDir = std::make_unique<QTemporaryDir>(pattern);
+}
+
+QString TemporaryDirectory::masterDirectoryPath()
+{
+ return m_masterTemporaryDir->path();
+}
+
+} // namespace Utils