diff options
| author | Peter Penz <[email protected]> | 2011-01-16 19:51:48 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-01-16 19:51:48 +0000 |
| commit | 38719e5dfdf1887d7e08f6b36ebf9c87c262a016 (patch) | |
| tree | 54481e79de7114fdef9c42518b8937475eb50133 /src | |
| parent | e5a0ce83fdd6ea02598df8dece4ce9c89bfd6240 (diff) | |
Remember all iterated directories to prevent an endless recursion by links. Tested with search all files below /
svn path=/trunk/KDE/kdebase/apps/; revision=1214895
Diffstat (limited to 'src')
| -rw-r--r-- | src/search/filenamesearchprotocol.cpp | 42 | ||||
| -rw-r--r-- | src/search/filenamesearchprotocol.h | 2 |
2 files changed, 29 insertions, 15 deletions
diff --git a/src/search/filenamesearchprotocol.cpp b/src/search/filenamesearchprotocol.cpp index 8464205ff..4670888aa 100644 --- a/src/search/filenamesearchprotocol.cpp +++ b/src/search/filenamesearchprotocol.cpp @@ -34,20 +34,19 @@ FileNameSearchProtocol::FileNameSearchProtocol( const QByteArray &pool, const QByteArray &app ) : SlaveBase("search", pool, app), m_checkContent(false), - m_regExp(0) + m_regExp(0), + m_iteratedDirs() { } FileNameSearchProtocol::~FileNameSearchProtocol() { - delete m_regExp; - m_regExp = 0; + cleanup(); } void FileNameSearchProtocol::listDir(const KUrl& url) { - delete m_regExp; - m_regExp = 0; + cleanup(); const QString search = url.queryItem("search"); if (!search.isEmpty()) { @@ -63,11 +62,17 @@ void FileNameSearchProtocol::listDir(const KUrl& url) const QString urlString = url.queryItem("url"); searchDirectory(KUrl(urlString)); + cleanup(); finished(); } void FileNameSearchProtocol::searchDirectory(const KUrl& directory) { + if (directory.path() == QLatin1String("/proc")) { + // Don't try to iterate the /proc directory of Linux + return; + } + // Get all items of the directory KDirLister *dirLister = new KDirLister(); dirLister->setDelayedMimeTypes(false); @@ -97,22 +102,22 @@ void FileNameSearchProtocol::searchDirectory(const KUrl& directory) } if (item.isDir()) { - bool skipDir = false; - const KUrl itemDir = item.url(); if (item.isLink()) { - // Assure that no endless searching is done if a link points - // to a parent directory - const KUrl linkDestDir = item.linkDest(); - skipDir = linkDestDir.isParentOf(itemDir); - } - - if (!skipDir) { - pendingDirs.append(itemDir); + // Assure that no endless searching is done in directories that + // have already been iterated. + const KUrl linkDest(item.url(), item.linkDest()); + if (!m_iteratedDirs.contains(linkDest.path())) { + pendingDirs.append(linkDest); + } + } else { + pendingDirs.append(item.url()); } } } listEntry(KIO::UDSEntry(), true); + m_iteratedDirs.insert(directory.path()); + delete dirLister; dirLister = 0; @@ -162,6 +167,13 @@ bool FileNameSearchProtocol::contentContainsPattern(const KUrl& fileName) const return false; } +void FileNameSearchProtocol::cleanup() +{ + delete m_regExp; + m_regExp = 0; + m_iteratedDirs.clear(); +} + extern "C" int KDE_EXPORT kdemain( int argc, char **argv ) { KComponentData instance("kio_search"); diff --git a/src/search/filenamesearchprotocol.h b/src/search/filenamesearchprotocol.h index b2d64d6e3..4a854d729 100644 --- a/src/search/filenamesearchprotocol.h +++ b/src/search/filenamesearchprotocol.h @@ -50,9 +50,11 @@ private: */ bool contentContainsPattern(const KUrl& fileName) const; + void cleanup(); bool m_checkContent; QRegExp* m_regExp; + QSet<QString> m_iteratedDirs; }; #endif |
