diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2011-08-11 13:49:37 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2011-08-26 12:06:42 (GMT) |
commit | dcee6e1371d899eb79717b8e3f3eec08b765db82 (patch) | |
tree | f34d4d7d6a05fb1939fbcb5d707496fdea095b38 | |
parent | 7b693627ee2a17718cb6d8bee5e3deb5a97b307f (diff) | |
download | Qt-dcee6e1371d899eb79717b8e3f3eec08b765db82.zip Qt-dcee6e1371d899eb79717b8e3f3eec08b765db82.tar.gz Qt-dcee6e1371d899eb79717b8e3f3eec08b765db82.tar.bz2 |
Fix QDir::operator==(const QDir &) const
We can't rely on absolute paths when comparing directories for equality
as these don't take into account symbolic links and may also bypass ../
and ./ simplification.
Instead, canonical paths must be computed and can then be compared
according to the case sensitivity rules for the platform or file engine,
as is done in QFileInfo.
Task-number: QTBUG-20495
Reviewed-by: Prasanth Ullattil
-rw-r--r-- | src/corelib/io/qdir.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 1 | ||||
-rw-r--r-- | tests/auto/qdir/tst_qdir.cpp | 6 |
3 files changed, 10 insertions, 3 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index f9196e0..6e25d91 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -1633,9 +1633,9 @@ bool QDir::operator==(const QDir &dir) const if (d->filters == other->filters && d->sort == other->sort && d->nameFilters == other->nameFilters) { - d->resolveAbsoluteEntry(); - other->resolveAbsoluteEntry(); - return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0; + + // Fallback to expensive canonical path computation + return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0; } return false; } diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index ca42c87..6e25206 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -406,6 +406,7 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const if (fileinfo.size() != size()) //if the size isn't the same... return false; + // Fallback to expensive canonical path computation return canonicalFilePath().compare(fileinfo.canonicalFilePath(), sensitive) == 0; } diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp index 0a42a97..419eaae 100644 --- a/tests/auto/qdir/tst_qdir.cpp +++ b/tests/auto/qdir/tst_qdir.cpp @@ -444,9 +444,15 @@ void tst_QDir::QDir_default() void tst_QDir::compare() { // operator== + + // Not using QCOMPARE to test result of QDir::operator== + QDir dir; dir.makeAbsolute(); QVERIFY(dir == QDir::currentPath()); + + QVERIFY(QDir() == QDir(QDir::currentPath())); + QVERIFY(QDir("../") == QDir(QDir::currentPath() + "/..")); } static QStringList filterLinks(const QStringList &list) |