summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qtemporaryfile.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@nokia.com>2012-05-30 11:55:28 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-05 06:15:06 +0200
commitf3f648f920a9f4676a5cde98806fc7735119984c (patch)
treea0deb0ffd433a8dc8606bb50e6adfde454969131 /src/corelib/io/qtemporaryfile.cpp
parent872f0b94ac7a863c59bf1175b94cca3b3636cf13 (diff)
Fix QTemporaryFile::open() failing after remove().
If a QTemporaryFile is constructed using a template file path, the path is generated in QTemporaryFileEngine::open() and then filePathIsTemplate is set to false. If remove() and then open() are called on the same QTemporaryFile, the path is not regenerated. This change ensures that if the file path was generated, it will be generated again in the scenario above. Task-number: QTBUG-2557 Change-Id: I718ceb89daa9a9d46fdbe811fecc3d57d6dc08c2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index cb8b5dbefc..56b3d17dc1 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -223,7 +223,8 @@ class QTemporaryFileEngine : public QFSFileEngine
Q_DECLARE_PRIVATE(QFSFileEngine)
public:
QTemporaryFileEngine(const QString &file, bool fileIsTemplate = true)
- : QFSFileEngine(), filePathIsTemplate(fileIsTemplate)
+ : QFSFileEngine(), filePathIsTemplate(fileIsTemplate),
+ filePathWasTemplate(fileIsTemplate)
{
Q_D(QFSFileEngine);
d->fileEntry = QFileSystemEntry(file);
@@ -244,6 +245,7 @@ public:
bool close();
bool filePathIsTemplate;
+ bool filePathWasTemplate;
};
QTemporaryFileEngine::~QTemporaryFileEngine()
@@ -379,6 +381,12 @@ bool QTemporaryFileEngine::remove()
QFSFileEngine::close();
if (QFSFileEngine::remove()) {
d->fileEntry.clear();
+ // If a QTemporaryFile is constructed using a template file path, the path
+ // is generated in QTemporaryFileEngine::open() and then filePathIsTemplate
+ // is set to false. If remove() and then open() are called on the same
+ // QTemporaryFile, the path is not regenerated. Here we ensure that if the
+ // file path was generated, it will be generated again in the scenario above.
+ filePathIsTemplate = filePathWasTemplate;
return true;
}
return false;