summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qtemporaryfile.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-11-07 14:08:54 -0800
committerJani Heikkinen <jani.heikkinen@qt.io>2017-11-23 05:27:23 +0000
commit4be50ecafd3cc63469504aaae8ac28ff0736989d (patch)
tree4eded8d8605f47653d540dc095be2c6ccbc49065 /src/corelib/io/qtemporaryfile.cpp
parent42005951defded6cd1a9a60582b29f58c78fea9e (diff)
QTemporaryFile: fix issues with removing a file twice
The assertion in isUnnamedFile() we had was incorrect after the file was removed, since we cleared the name and possibly reset back to the template. Since ~QTemporaryFile() calls remove(), this was easy to trigger if you attempted to remove the temp file and leave QTemporaryFile like that. Take this opportunity to add to the docs of setAutoRemove() explaining the possibility of unnamed files. #7 0x00007f69bcc2b50e in qt_assert ( assertion=assertion@entry=0x7f69bcf194a0 "unnamedFile == d_func()->fileEntry.isEmpty()", file=file@entry=0x7f69bcf19458 "io/qtemporaryfile.cpp", line=line@entry=514) at global/qglobal.cpp:3123 #8 0x00007f69bcd672cf in QTemporaryFileEngine::isUnnamedFile (this=this@entry=0x55cd60644df0) at io/qtemporaryfile.cpp:514 #9 0x00007f69bcd683f7 in QTemporaryFileEngine::remove (this=0x55cd60644df0) at io/qtemporaryfile.cpp:396 #10 0x00007f69bcd48654 in QFile::remove (this=this@entry=0x7fffb393f7e0) at io/qfile.cpp:513 #11 0x00007f69bcd6653b in QTemporaryFile::~QTemporaryFile (this=0x7fffb393f7e0, __in_chrg=<optimized out>) at io/qtemporaryfile.cpp:719 Change-Id: I57a1bd6e0c194530b732fffd14f4ed28ca8185b2 Reviewed-by: Andreas Hartmetz <ahartmetz@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index b8d3e859cf..35699d52df 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -393,7 +393,9 @@ bool QTemporaryFileEngine::remove()
// we must explicitly call QFSFileEngine::close() before we remove it.
d->unmapAll();
QFSFileEngine::close();
- if (isUnnamedFile() || QFSFileEngine::remove()) {
+ if (isUnnamedFile())
+ return true;
+ if (!filePathIsTemplate && 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
@@ -511,7 +513,10 @@ bool QTemporaryFileEngine::materializeUnnamedFile(const QString &newName, QTempo
bool QTemporaryFileEngine::isUnnamedFile() const
{
#ifdef LINUX_UNNAMED_TMPFILE
- Q_ASSERT(unnamedFile == d_func()->fileEntry.isEmpty());
+ if (unnamedFile) {
+ Q_ASSERT(d_func()->fileEntry.isEmpty());
+ Q_ASSERT(filePathIsTemplate);
+ }
return unnamedFile;
#else
return false;
@@ -749,10 +754,21 @@ bool QTemporaryFile::autoRemove() const
}
/*!
- Sets the QTemporaryFile into auto-remove mode if \a b is true.
+ Sets the QTemporaryFile into auto-remove mode if \a b is \c true.
Auto-remove is on by default.
+ If you set this property to \c false, ensure the application provides a way
+ to remove the file once it is no longer needed, including passing the
+ responsibility on to another process. Always use the fileName() function to
+ obtain the name and never try to guess the name that QTemporaryFile has
+ generated.
+
+ On some systems, if fileName() is not called before closing the file, the
+ temporary file may be removed regardless of the state of this property.
+ This behavior should not be relied upon, so application code should either
+ call fileName() or leave the auto removal functionality enabled.
+
\sa autoRemove(), remove()
*/
void QTemporaryFile::setAutoRemove(bool b)