summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-05-18 16:40:03 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-05-22 12:33:45 (GMT)
commit27369e563263e82a9c5747da54370eb0a225b3d5 (patch)
tree13a15e470653e77b14dca81b0c090e3e516124a0 /src/corelib/io
parentf1793cbff8aa9b4adcb5fd511e495f7e96811e2b (diff)
downloadQt-27369e563263e82a9c5747da54370eb0a225b3d5.zip
Qt-27369e563263e82a9c5747da54370eb0a225b3d5.tar.gz
Qt-27369e563263e82a9c5747da54370eb0a225b3d5.tar.bz2
QTemporaryFile: really (re)open file if it has been really closed...
In some circumstances, the file descriptor in QTemporaryFile is actually closed and setOpenMode alone won't give us reOpen semantics. Added function to QTemporaryFileEngine that checks if we have open file handles. On open, if we currently hold no handles, re-open the file. Trying to open a new file while we hold open handles would lead to leaks, so added an assert there, to be on the safe side. Reviewed-by: Thiago
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 3f8f978..5e08ed8 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -294,6 +294,7 @@ public:
QTemporaryFileEngine(const QString &file) : QFSFileEngine(file) { }
~QTemporaryFileEngine();
+ bool isReallyOpen();
void setFileName(const QString &file);
bool open(QIODevice::OpenMode flags);
@@ -306,6 +307,21 @@ QTemporaryFileEngine::~QTemporaryFileEngine()
QFSFileEngine::close();
}
+bool QTemporaryFileEngine::isReallyOpen()
+{
+ Q_D(QFSFileEngine);
+
+ if (!((0 == d->fh) && (-1 == d->fd)
+#if defined Q_OS_WIN
+ && (INVALID_HANDLE_VALUE == d->fileHandle)
+#endif
+ ))
+ return true;
+
+ return false;
+
+}
+
void QTemporaryFileEngine::setFileName(const QString &file)
{
// Really close the file, so we don't leak
@@ -316,6 +332,7 @@ void QTemporaryFileEngine::setFileName(const QString &file)
bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
{
Q_D(QFSFileEngine);
+ Q_ASSERT(!isReallyOpen());
QString qfilename = d->filePath;
if(!qfilename.contains(QLatin1String("XXXXXX")))
@@ -716,8 +733,10 @@ bool QTemporaryFile::open(OpenMode flags)
{
Q_D(QTemporaryFile);
if (!d->fileName.isEmpty()) {
- setOpenMode(flags);
- return true;
+ if (static_cast<QTemporaryFileEngine*>(fileEngine())->isReallyOpen()) {
+ setOpenMode(flags);
+ return true;
+ }
}
flags |= QIODevice::ReadWrite;