summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qfileinfo_p.h5
-rw-r--r--src/corelib/io/qfilesystemiterator_symbian.cpp10
-rw-r--r--tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp93
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 <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"