Make sure we don't cache old file sizes prior to new writes
If we write to a file, its size changes. We should drop previous size caches. Change-Id: Ib687c91e5fc88cab588c89023f23da9622160da9 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>bb10
parent
c6718f01c2
commit
4848796f3e
|
|
@ -742,6 +742,9 @@ qint64 QFSFileEnginePrivate::writeFdFh(const char *data, qint64 len)
|
|||
if (len && writtenBytes == 0) {
|
||||
writtenBytes = -1;
|
||||
q->setError(errno == ENOSPC ? QFile::ResourceError : QFile::WriteError, qt_error_string(errno));
|
||||
} else {
|
||||
// reset the cached size, if any
|
||||
metaData.clearFlags(QFileSystemMetaData::SizeAttribute);
|
||||
}
|
||||
|
||||
return writtenBytes;
|
||||
|
|
|
|||
|
|
@ -234,6 +234,8 @@ private slots:
|
|||
void mapResource();
|
||||
void mapOpenMode_data();
|
||||
void mapOpenMode();
|
||||
void mapWrittenFile_data();
|
||||
void mapWrittenFile();
|
||||
|
||||
#ifndef Q_OS_WINCE
|
||||
void openStandardStreamsFileDescriptors();
|
||||
|
|
@ -3079,6 +3081,44 @@ void tst_QFile::mapOpenMode()
|
|||
file.close();
|
||||
}
|
||||
|
||||
void tst_QFile::mapWrittenFile_data()
|
||||
{
|
||||
QTest::addColumn<int>("mode");
|
||||
QTest::newRow("buffered") << 0;
|
||||
QTest::newRow("unbuffered") << int(QIODevice::Unbuffered);
|
||||
}
|
||||
|
||||
void tst_QFile::mapWrittenFile()
|
||||
{
|
||||
static const char data[128] = "Some data padded with nulls\n";
|
||||
QFETCH(int, mode);
|
||||
|
||||
QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile";
|
||||
|
||||
#ifdef Q_OS_WINCE
|
||||
fileName = QFileInfo(fileName).absoluteFilePath();
|
||||
#endif
|
||||
|
||||
if (QFile::exists(fileName)) {
|
||||
QVERIFY(QFile::setPermissions(fileName,
|
||||
QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser));
|
||||
QFile::remove(fileName);
|
||||
}
|
||||
QFile file(fileName);
|
||||
QVERIFY(file.open(QIODevice::ReadWrite | QFile::OpenMode(mode)));
|
||||
QCOMPARE(file.write(data, sizeof data), qint64(sizeof data));
|
||||
if ((mode & QIODevice::Unbuffered) == 0)
|
||||
file.flush();
|
||||
|
||||
// test that we can read the data we've just written, without closing the file
|
||||
uchar *memory = file.map(0, sizeof data);
|
||||
QVERIFY(memory);
|
||||
QVERIFY(memcmp(memory, data, sizeof data) == 0);
|
||||
|
||||
file.close();
|
||||
file.remove();
|
||||
}
|
||||
|
||||
void tst_QFile::openDirectory()
|
||||
{
|
||||
QFile f1(m_resourcesDir);
|
||||
|
|
|
|||
Loading…
Reference in New Issue