diff options
author | João Abecasis <joao@abecasis.name> | 2009-05-18 18:24:20 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-05-22 12:33:47 (GMT) |
commit | 1044e75822270d702a3e9f14a87954321984c942 (patch) | |
tree | b925b24047db24129aba0dcf552c46763675c5e5 | |
parent | 84cbe8ffa4a7189c46efca9bb6387e80ab889c5c (diff) | |
download | Qt-1044e75822270d702a3e9f14a87954321984c942.zip Qt-1044e75822270d702a3e9f14a87954321984c942.tar.gz Qt-1044e75822270d702a3e9f14a87954321984c942.tar.bz2 |
QTemporaryFileEngine now tracks if a fileName has been generated
With recent changes to QTemporaryFile, allowing the file to be closed,
the engine has to keep track of whether a fileName has already been
generated, so we don't generate new files after the first one.
If the file is closed but we already have a name for it, then just
forward the call to the base file engine.
Reviewed-by: Thiago
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index ec539d4..564ec59 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -291,7 +291,11 @@ class QTemporaryFileEngine : public QFSFileEngine { Q_DECLARE_PRIVATE(QFSFileEngine) public: - QTemporaryFileEngine(const QString &file) : QFSFileEngine(file) { } + QTemporaryFileEngine(const QString &file, bool fileIsTemplate = true) + : QFSFileEngine(file), filePathIsTemplate(fileIsTemplate) + { + } + ~QTemporaryFileEngine(); bool isReallyOpen(); @@ -300,6 +304,8 @@ public: bool open(QIODevice::OpenMode flags); bool remove(); bool close(); + + bool filePathIsTemplate; }; QTemporaryFileEngine::~QTemporaryFileEngine() @@ -334,6 +340,9 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) Q_D(QFSFileEngine); Q_ASSERT(!isReallyOpen()); + if (!filePathIsTemplate) + return QFSFileEngine::open(openMode); + QString qfilename = d->filePath; if(!qfilename.contains(QLatin1String("XXXXXX"))) qfilename += QLatin1String(".XXXXXX"); @@ -353,6 +362,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) // Restore the file names (open() resets them). d->filePath = QString::fromLocal8Bit(filename); //changed now! + filePathIsTemplate = false; d->nativeInitFileName(); delete [] filename; return true; @@ -370,6 +380,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) } d->filePath = QString::fromLocal8Bit(filename); + filePathIsTemplate = false; d->nativeInitFileName(); d->closeFileHandle = true; delete [] filename; @@ -714,8 +725,12 @@ QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file) QAbstractFileEngine *QTemporaryFile::fileEngine() const { Q_D(const QTemporaryFile); - if(!d->fileEngine) - d->fileEngine = new QTemporaryFileEngine(d->templateName); + if(!d->fileEngine) { + if (d->fileName.isEmpty()) + d->fileEngine = new QTemporaryFileEngine(d->templateName); + else + d->fileEngine = new QTemporaryFileEngine(d->fileName, false); + } return d->fileEngine; } |