Cleanup after the qsf cache file if it fails to be written to

It is possible that although a qsf cache file could be opened that it
could not be written to, therefore it should clean up after itself in
these cases so that it does not cause a problem later on.

Task-number: QTBUG-24122
Change-Id: I1999759837607657ddc3f967eeda370ce9991a16
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
This commit is contained in:
Andy Shaw 2012-03-06 10:39:34 +01:00 committed by Qt by Nokia
parent 13c57d0f68
commit 0850b5d76a

View File

@ -246,6 +246,17 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
int fd = QT_OPEN(fileName.constData(), O_RDONLY, 0);
if (fd >= 0) {
QT_STATBUF st;
int nDataSize = 0;
if (QT_FSTAT(fd, &st)) {
#if defined(DEBUG_FONTENGINE)
qDebug() << "stat failed! " << fileName;
#endif
} else {
nDataSize = st.st_size;
}
if (nDataSize >= (int)sizeof(QFontEngineQPF::Header)) {
void *header = ::mmap(0, sizeof(QFontEngineQPF::Header), PROT_READ, MAP_SHARED, fd, 0);
if (header && header != MAP_FAILED) {
quint32 lockValue = reinterpret_cast<QFontEngineQPF::Header *>(header)->lock;
@ -257,6 +268,11 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
::munmap(header, sizeof(QFontEngineQPF::Header));
}
} else {
#if defined(DEBUG_FONTENGINE)
qDebug() << "Unsufficient header data in QSF file " << fileName;
#endif
}
QT_CLOSE(fd);
}
}
@ -363,6 +379,7 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng
#if defined(DEBUG_FONTENGINE)
qErrnoWarning(errno, "QFontEngineQPF: write() failed for %s", encodedName.constData());
#endif
QFile::remove(fileName);
return;
}
} else {