Fixed: QFileInfo::lastModified() returning wrong value.

Fixed so that empty QDateTime is returned for non existing file.
Fixed also created() and lastRead() to return empty QDateTime for
non existing file.

QFileSystemEngine::fillMetaData() returned true for non existing
files. This was also corrected.

Task-number: QTBUG-25811

Change-Id: I523eb99e4405b4b813b2950f85cc646239181d07
Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org>
Reviewed-by: Christian Stromme <christian.stromme@nokia.com>
This commit is contained in:
Markku Heikkila 2012-06-05 15:50:13 +03:00 committed by Qt by Nokia
parent a42f1f9a50
commit d1d4647b74
4 changed files with 24 additions and 5 deletions

View File

@ -1259,7 +1259,8 @@ QDateTime QFileInfo::created() const
return QDateTime(); return QDateTime();
if (d->fileEngine == 0) { if (d->fileEngine == 0) {
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::CreationTime)) if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::CreationTime))
QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::CreationTime); if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::CreationTime))
return QDateTime();
return d->metaData.creationTime(); return d->metaData.creationTime();
} }
return d->getFileTime(QAbstractFileEngine::CreationTime); return d->getFileTime(QAbstractFileEngine::CreationTime);
@ -1277,7 +1278,8 @@ QDateTime QFileInfo::lastModified() const
return QDateTime(); return QDateTime();
if (d->fileEngine == 0) { if (d->fileEngine == 0) {
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::ModificationTime)) if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::ModificationTime))
QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::ModificationTime); if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::ModificationTime))
return QDateTime();
return d->metaData.modificationTime(); return d->metaData.modificationTime();
} }
return d->getFileTime(QAbstractFileEngine::ModificationTime); return d->getFileTime(QAbstractFileEngine::ModificationTime);
@ -1298,7 +1300,8 @@ QDateTime QFileInfo::lastRead() const
return QDateTime(); return QDateTime();
if (d->fileEngine == 0) { if (d->fileEngine == 0) {
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::AccessTime)) if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::AccessTime))
QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::AccessTime); if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::AccessTime))
return QDateTime();
return d->metaData.accessTime(); return d->metaData.accessTime();
} }
return d->getFileTime(QAbstractFileEngine::AccessTime); return d->getFileTime(QAbstractFileEngine::AccessTime);

View File

@ -467,7 +467,10 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
data.knownFlagsMask |= QFileSystemMetaData::BundleType; data.knownFlagsMask |= QFileSystemMetaData::BundleType;
} }
#endif #endif
if (!entryExists) {
data.clearFlags(what);
return false;
}
return data.hasFlags(what); return data.hasFlags(what);
} }

View File

@ -856,7 +856,10 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
data.fillFromFindData(findData, false, fname.isDriveRoot()); data.fillFromFindData(findData, false, fname.isDriveRoot());
} else { } else {
if (!tryFindFallback(fname, data)) if (!tryFindFallback(fname, data))
tryDriveUNCFallback(fname, data); if (!tryDriveUNCFallback(fname, data)) {
SetErrorMode(oldmode);
return false;
}
} }
SetErrorMode(oldmode); SetErrorMode(oldmode);
} }

View File

@ -189,6 +189,7 @@ private slots:
void group(); void group();
void invalidState(); void invalidState();
void nonExistingFileDates();
}; };
void tst_QFileInfo::cleanupTestCase() void tst_QFileInfo::cleanupTestCase()
@ -1819,5 +1820,14 @@ void tst_QFileInfo::invalidState()
QVERIFY(true); QVERIFY(true);
} }
void tst_QFileInfo::nonExistingFileDates()
{
QFileInfo info("non-existing-file.foobar");
QVERIFY(!info.exists());
QVERIFY(!info.created().isValid());
QVERIFY(!info.lastRead().isValid());
QVERIFY(!info.lastModified().isValid());
}
QTEST_MAIN(tst_QFileInfo) QTEST_MAIN(tst_QFileInfo)
#include "tst_qfileinfo.moc" #include "tst_qfileinfo.moc"