From 3864ad09d578210b52e5f58fca2ee8a1144f5be2 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Tue, 17 Jan 2012 19:51:39 +0000 Subject: Fix BC break with QAbstractFileEngine "mount points" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/io/qfileinfo_p.h | 5 ++ src/corelib/io/qfilesystemiterator_symbian.cpp | 10 ++- .../tst_qabstractfileengine.cpp | 93 +++++++++++++++++++++- 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h index 64e644f..a68866f 100644 --- a/src/corelib/io/qfileinfo_p.h +++ b/src/corelib/io/qfileinfo_p.h @@ -108,10 +108,15 @@ public: : QSharedData(), fileEntry(file), metaData(data), + fileEngine(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(fileEntry, metaData)), cachedFlags(0), isDefaultConstructed(false), cache_enabled(true), fileFlags(0), fileSize(0) { + //If the file engine is not null, this maybe a "mount point" for a custom file engine + //in which case we can't trust the metadata + if (fileEngine) + metaData = QFileSystemMetaData(); } inline void clearFlags() const { diff --git a/src/corelib/io/qfilesystemiterator_symbian.cpp b/src/corelib/io/qfilesystemiterator_symbian.cpp index 2a58770..82dfd87 100644 --- a/src/corelib/io/qfilesystemiterator_symbian.cpp +++ b/src/corelib/io/qfilesystemiterator_symbian.cpp @@ -83,10 +83,12 @@ QFileSystemIterator::QFileSystemIterator(const QFileSystemEntry &path, QDir::Fil symbianMask |= KEntryAttHidden; if (filters & QDir::System) symbianMask |= KEntryAttSystem; - if (((filters & QDir::Files) == 0) && symbianMask == KEntryAttDir) - symbianMask |= KEntryAttMatchExclusive; //exclude non-directories - else if (symbianMask == 0) { - if ((filters & QDir::PermissionMask) == QDir::Writable) + //Do not use KEntryAttMatchExclusive to optimise to return only + //directories for QDir::Dirs. There may be a file which is actually + //a "mount point" for a file engine and needs to be returned so it + //can be overriden to be a directory, see QTBUG-23688 + if (symbianMask == 0 + && ((filters & QDir::PermissionMask) == QDir::Writable)) { symbianMask = KEntryAttMatchExclude | KEntryAttReadOnly; } 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 #include #include +#include +#include #include #include +#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 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 ReferenceFileEngine::fileSystemUsers, ReferenceFileEngine::fileSystemGroups; QHash > 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("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" -- cgit v0.12