Example #1
0
/*!
    \internal
*/
void QDirIteratorPrivate::advance()
{
    while (!fileEngineIterators.isEmpty()) {

        // Find the next valid iterator that matches the filters.
        while (fileEngineIterators.top()->hasNext()) {
            QAbstractFileEngineIterator *it = fileEngineIterators.top();
            it->next();

            const QFileInfo info = it->currentFileInfo();
            checkAndPushDirectory(it->currentFileInfo());

            if (matchesFilters(it->currentFileName(), info)) {
                currentFileInfo = nextFileInfo;
                nextFileInfo = info;

                //We found a matching entry.
                return;
            }
        }

        delete fileEngineIterators.pop();
    }

    currentFileInfo = nextFileInfo;
    nextFileInfo = QFileInfo();
}
Example #2
0
/*!
    \internal
*/
void QDirIteratorPrivate::advance()
{
    // Store the current entry
    if (!fileEngineIterators.isEmpty())
        currentFilePath = fileEngineIterators.top()->currentFilePath();

    // 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 (currentFileInfo.isSymLink())
            subDir = currentFileInfo.canonicalFilePath();
#endif
        pushSubDirectory(subDir, it->nameFilters(), it->filters());
    }

    while (!fileEngineIterators.isEmpty()) {
        QAbstractFileEngineIterator *it = fileEngineIterators.top();

        // Find the next valid iterator that matches the filters.
        bool foundDirectory = false;
        while (it->hasNext()) {
            it->next();
            if (matchesFilters(it)) {
                currentFileInfo = nextFileInfo;
                nextFileInfo = it->currentFileInfo();
                // Signal that we want to follow this entry.
                followNextDir = shouldFollowDirectory(nextFileInfo);
                //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());
                
                foundDirectory = true;
                break;
            }
        }
        if (!foundDirectory)
            delete fileEngineIterators.pop();
    }
    currentFileInfo = nextFileInfo;
    done = true;
}
Example #3
0
/*!
    \internal
*/
void QDirIteratorPrivate::advance()
{
    if (engine) {
        while (!fileEngineIterators.isEmpty()) {
            // Find the next valid iterator that matches the filters.
            QAbstractFileEngineIterator *it;
            while (it = fileEngineIterators.top(), it->hasNext()) {
                it->next();
                if (entryMatches(it->currentFileName(), it->currentFileInfo()))
                    return;
            }

            fileEngineIterators.pop();
            delete it;
        }
    } else {
#ifndef QT_NO_FILESYSTEMITERATOR
        QFileSystemEntry nextEntry;
        QFileSystemMetaData nextMetaData;

        while (!nativeIterators.isEmpty()) {
            // Find the next valid iterator that matches the filters.
            QFileSystemIterator *it;
            while (it = nativeIterators.top(), it->advance(nextEntry, nextMetaData)) {
                QFileInfo info(new QFileInfoPrivate(nextEntry, nextMetaData));

                if (entryMatches(nextEntry.fileName(), info))
                    return;
            }

            nativeIterators.pop();
            delete it;
        }
#endif
    }

    currentFileInfo = nextFileInfo;
    nextFileInfo = QFileInfo();
}
Example #4
0
/*!
    \internal
*/
void QDirIteratorPrivate::advance()
{
    // Store the current entry
    if (!fileEngineIterators.isEmpty())
        currentFilePath = fileEngineIterators.top()->currentFilePath();

    // 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 (fileInfo.isSymLink())
            subDir = fileInfo.canonicalFilePath();
#endif
        pushSubDirectory(subDir, it->nameFilters(), it->filters());
    }

    if (fileEngineIterators.isEmpty())
        done = true;

    bool foundValidEntry = false;
    while (!fileEngineIterators.isEmpty()) {
        QAbstractFileEngineIterator *it = fileEngineIterators.top();

        // Find the next valid iterator that matches the filters.
        foundValidEntry = false;
        while (it->hasNext()) {
            it->next();
            if (matchesFilters(it)) {
                foundValidEntry = true;
                break;
            }
        }

        if (!foundValidEntry) {
            // If this iterator is done, pop and delete it, and continue
            // iteration on the parent. Otherwise break, we're done.
            if (!fileEngineIterators.isEmpty()) {
                delete it;
                it = fileEngineIterators.pop();
                continue;
            }
            break;
        }

        fileInfo = it->currentFileInfo();

        // If we're doing flat iteration, we're done.
        if (!(iteratorFlags & QDirIterator::Subdirectories))
            break;

        // Subdirectory iteration.
        QString filePath = fileInfo.filePath();

        // Never follow . and ..
        if (fileInfo.fileName() == QLatin1String(".") || fileInfo.fileName() == QLatin1String(".."))
            break;

        // Never follow non-directory entries
        if (!fileInfo.isDir())
            break;
      
        // Check symlinks
        if (fileInfo.isSymLink() && !(iteratorFlags & QDirIterator::FollowSymlinks)) {
            // Follow symlinks only if FollowSymlinks was passed
            break;
        }

        // Stop link loops
        if (visitedLinks.contains(fileInfo.canonicalFilePath()))
            break;

        // Signal that we want to follow this entry.
        followNextDir = true;
        break;
    }

    if (!foundValidEntry)
        done = true;
}