Flush in `File::write` when in unbuffered "text" mode

If the wrapped `QFile` was opened with `QIODevice::Unbuffered`, any
writes should be unbuffered.  However, as currently implemented,
using `QTextStream` when the `File` is in "text" mode causes all
reads/writes to be buffered.

This modification forces a flush in `File::write` if the wrapped
`QFile` was opened with `QIODevice::Unbuffered`.

Necessary to fix issue #11162 https://github.com/ariya/phantomjs/issues/11162.
1.x
execjosh 2013-03-26 13:05:25 +09:00 committed by Ariya Hidayat
parent 24078b56c7
commit 8042f3b92c
2 changed files with 12 additions and 0 deletions

View File

@ -123,6 +123,9 @@ bool File::write(const QString &data)
if ( m_fileStream ) {
// text file
(*m_fileStream) << data;
if (_isUnbuffered()) {
m_fileStream->flush();
}
return true;
} else {
// binary file
@ -213,6 +216,13 @@ void File::close()
deleteLater();
}
// private:
bool File::_isUnbuffered() const
{
return m_file->openMode() & QIODevice::Unbuffered;
}
// FileSystem
// public:

View File

@ -65,6 +65,8 @@ public slots:
void close();
private:
bool _isUnbuffered() const;
QFile *m_file;
QTextStream *m_fileStream;
};