summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qdir.cpp15
-rw-r--r--tests/auto/qdir/tst_qdir.cpp22
2 files changed, 34 insertions, 3 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 3271148..9081e31 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -1638,8 +1638,19 @@ bool QDir::operator==(const QDir &dir) const
if (d->dirEntry.filePath() == other->dirEntry.filePath())
return true;
- // Fallback to expensive canonical path computation
- return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
+ if (exists()) {
+ if (!dir.exists())
+ return false; //can't be equal if only one exists
+ // Both exist, fallback to expensive canonical path computation
+ return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
+ } else {
+ if (dir.exists())
+ return false; //can't be equal if only one exists
+ // Neither exists, compare absolute paths rather than canonical (which would be empty strings)
+ d->resolveAbsoluteEntry();
+ other->resolveAbsoluteEntry();
+ return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0;
+ }
}
return false;
}
diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp
index 7e5ec79..9693480 100644
--- a/tests/auto/qdir/tst_qdir.cpp
+++ b/tests/auto/qdir/tst_qdir.cpp
@@ -1951,10 +1951,30 @@ void tst_QDir::equalityOperator_data()
<< "." << "*.cpp" << int(QDir::Name) << int(QDir::Files)
<< true;
- QTest::newRow("QTBUG-20495-root") << QDir::rootPath() + "tmp/.." << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ //need a path in the root directory that is unlikely to be a symbolic link.
+#if defined (Q_OS_WIN)
+ QString pathinroot("c:/windows/..");
+#elif defined (Q_OS_SYMBIAN)
+ QString pathinroot("c:/data/..");
+#else
+ QString pathinroot("/sbin/..");
+#endif
+ QTest::newRow("QTBUG-20495-root") << pathinroot << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << QDir::rootPath() << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << true;
+
+ QTest::newRow("slashdot") << QDir::rootPath() + "." << "*.cpp" << int(QDir::Name) << int(QDir::Files)
<< QDir::rootPath() << "*.cpp" << int(QDir::Name) << int(QDir::Files)
<< true;
+ QTest::newRow("slashdotslash") << QDir::rootPath() + "./" << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << QDir::rootPath() << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << true;
+
+ QTest::newRow("nonexistantpaths") << "dir-that-dont-exist" << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << "another-dir-that-dont-exist" << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << false;
+
QTest::newRow("diff-filters") << SRCDIR << "*.cpp" << int(QDir::Name) << int(QDir::Files)
<< SRCDIR << "*.cpp" << int(QDir::Name) << int(QDir::Dirs)
<< false;