From c9579d44c6ce70066f90224c18ac964865290583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 16 Jul 2009 17:54:22 +0200 Subject: Refactoring QDirIteratorPrivate::pushSubDirectory pushSubDirectory was operating on nextFileInfo when it should really be using the path received as argument. This fixes an issue introduced when currentFilePath variable was removed, that was exposed in the auto-tests; fixes a regression introduced in 4.5.0 -- test case a couple of commits back. This also allows refactoring calling code and avoid repetition. Task-number: 258230 Reviewed-by: Olivier Goffart --- src/corelib/io/qdiriterator.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp index d372ed3..e48a1b9 100644 --- a/src/corelib/io/qdiriterator.cpp +++ b/src/corelib/io/qdiriterator.cpp @@ -106,7 +106,7 @@ public: QDir::Filters filters, QDirIterator::IteratorFlags flags); ~QDirIteratorPrivate(); - void pushSubDirectory(const QString &path, const QStringList &nameFilters, + void pushSubDirectory(const QFileInfo &fileInfo, const QStringList &nameFilters, QDir::Filters filters); void advance(); bool shouldFollowDirectory(const QFileInfo &); @@ -142,8 +142,7 @@ QDirIteratorPrivate::QDirIteratorPrivate(const QString &path, const QStringList this->nameFilters = nameFilters; nextFileInfo.setFile(path); - pushSubDirectory(nextFileInfo.isSymLink() ? nextFileInfo.canonicalFilePath() : path, - nameFilters, filters); + pushSubDirectory(nextFileInfo, nameFilters, filters); } /*! @@ -157,11 +156,18 @@ QDirIteratorPrivate::~QDirIteratorPrivate() /*! \internal */ -void QDirIteratorPrivate::pushSubDirectory(const QString &path, const QStringList &nameFilters, +void QDirIteratorPrivate::pushSubDirectory(const QFileInfo &fileInfo, const QStringList &nameFilters, QDir::Filters filters) { + QString path = fileInfo.filePath(); + +#ifdef Q_OS_WIN + if (fileInfo.isSymLink()) + path = fileInfo.canonicalFilePath(); +#endif + if (iteratorFlags & QDirIterator::FollowSymlinks) - visitedLinks << nextFileInfo.canonicalFilePath(); + visitedLinks << fileInfo.canonicalFilePath(); if (engine || (engine = QAbstractFileEngine::create(this->path))) { engine->setFileName(path); @@ -183,16 +189,9 @@ void QDirIteratorPrivate::advance() // Advance to the next entry if (followNextDir) { // Start by navigating into the current directory. - followNextDir = false; - QAbstractFileEngineIterator *it = fileEngineIterators.top(); - - QString subDir = it->currentFilePath(); -#ifdef Q_OS_WIN - if (nextFileInfo.isSymLink()) - subDir = nextFileInfo.canonicalFilePath(); -#endif - pushSubDirectory(subDir, it->nameFilters(), it->filters()); + pushSubDirectory(it->currentFileInfo(), it->nameFilters(), it->filters()); + followNextDir = false; } while (!fileEngineIterators.isEmpty()) { @@ -210,18 +209,8 @@ void QDirIteratorPrivate::advance() //We found a matching entry. return; - } else if (iteratorFlags & QDirIterator::Subdirectories) { - QFileInfo fileInfo = it->currentFileInfo(); - - if (!shouldFollowDirectory(fileInfo)) - continue; - QString subDir = it->currentFilePath(); -#ifdef Q_OS_WIN - if (fileInfo.isSymLink()) - subDir = fileInfo.canonicalFilePath(); -#endif - pushSubDirectory(subDir, it->nameFilters(), it->filters()); - + } else if (shouldFollowDirectory(it->currentFileInfo())) { + pushSubDirectory(it->currentFileInfo(), it->nameFilters(), it->filters()); foundDirectory = true; break; } -- cgit v0.12