diff options
author | Shane Kearns <ext-shane.2.kearns@nokia.com> | 2012-01-17 19:51:39 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-25 03:06:04 (GMT) |
commit | 3864ad09d578210b52e5f58fca2ee8a1144f5be2 (patch) | |
tree | d98f54d4f65aa8a6733be3788410ec5318615757 /tests/auto/qabstractfileengine | |
parent | 3aef11802c5f4ca0f3bde121e1704594f775bc33 (diff) | |
download | Qt-3864ad09d578210b52e5f58fca2ee8a1144f5be2.zip Qt-3864ad09d578210b52e5f58fca2ee8a1144f5be2.tar.gz Qt-3864ad09d578210b52e5f58fca2ee8a1144f5be2.tar.bz2 |
Fix BC break with QAbstractFileEngine "mount points"
File system cached metadata can't be trusted when custom file engines
are in use, because the custom file engine may want to override the
metadata. (e.g. present an archive file as a directory)
Therefore, check if a file engine should be instantiated for each
result in QDirIterator. This is a fast check if no custom file engines
are registered.
When pushing a directory (using QDirIterator::SubDirectories) the
file engine needs to be instantiated also.
Task-number: QTBUG-23688
Task-number: ou1cimx1#965023
Change-Id: I0114c8df6258535553783a2486131c4194926649
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'tests/auto/qabstractfileengine')
-rw-r--r-- | tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp b/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp index 20509c5..c526050 100644 --- a/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp +++ b/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp @@ -47,10 +47,13 @@ #include <QtCore/QSharedPointer> #include <QtCore/QScopedPointer> #include <QtCore/QHash> +#include <QtCore/QDir> +#include <QtCore/QDirIterator> #include <QtTest/QTest> #include <QtCore/QDebug> +#include "../../shared/filesystem.h" class tst_QAbstractFileEngine : public QObject @@ -65,6 +68,8 @@ private slots: void fileIO_data(); void fileIO(); + void mounting_data(); + void mounting(); private: QStringList filesForRemoval; }; @@ -74,7 +79,7 @@ class ReferenceFileEngine { public: ReferenceFileEngine(const QString &fileName) - : fileName_(fileName) + : fileName_(QDir::cleanPath(fileName)) , position_(-1) , openForRead_(false) , openForWrite_(false) @@ -491,6 +496,60 @@ private: mutable QSharedPointer<File> openFile_; }; +class MountingFileEngine : public QFSFileEngine +{ +public: + class Iterator : public QAbstractFileEngineIterator + { + public: + Iterator(QDir::Filters filters, const QStringList &filterNames) + : QAbstractFileEngineIterator(filters, filterNames) + { + names.append("foo"); + names.append("bar"); + index = -1; + } + QString currentFileName() const + { + return names.at(index); + } + bool hasNext() const + { + return index < names.size() - 1; + } + QString next() + { + if (!hasNext()) + return QString(); + ++index; + return currentFilePath(); + } + QStringList names; + int index; + }; + MountingFileEngine(QString fileName) + : QFSFileEngine(fileName) + { + } + Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) + { + return new Iterator(filters, filterNames); + } + FileFlags fileFlags(FileFlags type) const + { + if (fileName(DefaultName).endsWith(".tar")) { + FileFlags ret = QFSFileEngine::fileFlags(type); + //make this file in file system appear to be a directory + ret &= ~FileType; + ret |= DirectoryType; + return ret; + } else { + //file inside the archive + return ExistsFlag | FileType; + } + } +}; + QMutex ReferenceFileEngine::fileSystemMutex; QHash<uint, QString> ReferenceFileEngine::fileSystemUsers, ReferenceFileEngine::fileSystemGroups; QHash<QString, QSharedPointer<ReferenceFileEngine::File> > ReferenceFileEngine::fileSystem; @@ -500,6 +559,8 @@ class FileEngineHandler { QAbstractFileEngine *create(const QString &fileName) const { + if (fileName.endsWith(".tar") || fileName.contains(".tar/")) + return new MountingFileEngine(fileName); if (fileName.startsWith("QFSFileEngine:")) return new QFSFileEngine(fileName.mid(14)); if (fileName.startsWith("reference-file-engine:")) @@ -789,6 +850,36 @@ void tst_QAbstractFileEngine::fileIO() // } +void tst_QAbstractFileEngine::mounting_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::newRow("native") << "test.tar"; + QTest::newRow("Forced QFSFileEngine") << "QFSFileEngine:test.tar"; +} + +void tst_QAbstractFileEngine::mounting() +{ + FileSystem fs; + QVERIFY(fs.createFile("test.tar")); + FileEngineHandler handler; + + QFETCH(QString, fileName); + + QVERIFY(QFileInfo(fileName).isDir()); + QDir dir(fileName); + QCOMPARE(dir.entryList(), (QStringList() << "bar" << "foo")); + QDir dir2; + bool found = false; + foreach (QFileInfo info, dir2.entryInfoList()) { + if (info.fileName() == QLatin1String("test.tar")) { + QVERIFY(!found); + found = true; + QVERIFY(info.isDir()); + } + } + QVERIFY(found); +} + QTEST_APPLESS_MAIN(tst_QAbstractFileEngine) #include "tst_qabstractfileengine.moc" |