From e5057afe28441344d8c28dae20e4355e83977f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 21 Aug 2026 17:03:47 -0300 Subject: [PATCH] Fix indexing files added in new directories Scan newly added directory subtrees even after the initial project scan has finished, ensuring their files are added to ProjectDirectoryTree and become available to the universal locator. Preserve initial-scan cancellation, respect hidden-file settings and accepted patterns, and avoid inserting duplicate files. --- src/tools/ecode/projectdirectorytree.cpp | 47 ++++++++++++------------ src/tools/ecode/projectdirectorytree.hpp | 3 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/tools/ecode/projectdirectorytree.cpp b/src/tools/ecode/projectdirectorytree.cpp index a06640d8a..8d8da2691 100644 --- a/src/tools/ecode/projectdirectorytree.cpp +++ b/src/tools/ecode/projectdirectorytree.cpp @@ -341,12 +341,12 @@ void ProjectDirectoryTree::getDirectoryFiles( std::vector& files, std::vector& names, std::string directory, std::set currentDirs, const bool& ignoreHidden, IgnoreMatcherManager& ignoreMatcher, GitIgnoreMatcher* allowedMatcher, - GitIgnoreMatcher* disallowedMatcher ) { - if ( !mRunning ) + GitIgnoreMatcher* disallowedMatcher, bool initialScan ) { + if ( mClosing || ( initialScan && !mRunning ) ) return; currentDirs.insert( directory ); std::vector pathFiles = - FileSystem::filesGetInPath( directory, false, false, false ); + FileSystem::filesGetInPath( directory, false, false, ignoreHidden ); for ( auto& file : pathFiles ) { std::string fullpath( directory + file ); if ( ignoreMatcher.foundMatch() && ignoreMatcher.match( directory, file ) ) { @@ -393,7 +393,7 @@ void ProjectDirectoryTree::getDirectoryFiles( ignoreMatcher.addChild( childMatch ); } getDirectoryFiles( files, names, fullpath, currentDirs, ignoreHidden, ignoreMatcher, - allowedMatcher, disallowedMatcher ); + allowedMatcher, disallowedMatcher, initialScan ); if ( childMatch ) { ignoreMatcher.removeChild( childMatch ); eeSAFE_DELETE( childMatch ); @@ -461,31 +461,30 @@ void ProjectDirectoryTree::addFile( const FileInfo& file ) { return; Lock rl( mMatchingMutex ); Lock l( mFilesMutex ); + std::string directory( file.getFilepath() ); + FileSystem::dirAddSlashAtEnd( directory ); std::vector files; std::vector names; - std::vector patterns; std::set info; - if ( !mAcceptedPatterns.empty() ) { - getDirectoryFiles( files, names, mPath, info, false, mIgnoreMatcher, - mAllowedMatcher.get(), mDisallowedMatcher.get() ); - size_t namesCount = names.size(); - bool found; - for ( size_t i = 0; i < namesCount; i++ ) { - found = false; - for ( auto& pattern : patterns ) { - if ( pattern.matches( names[i] ) ) { - found = true; - break; - } - } - if ( found ) { - mFiles.emplace_back( std::move( files[i] ) ); - mNames.emplace_back( std::move( names[i] ) ); + IgnoreMatcherManager matcher( getIgnoreMatcherFromPath( directory ) ); + { + Lock ld( mDirectoriesMutex ); + mDirectories.emplace_back( directory ); + } + getDirectoryFiles( files, names, directory, info, mIgnoreHidden, matcher, + mAllowedMatcher.get(), mDisallowedMatcher.get(), false ); + for ( size_t i = 0; i < files.size(); ++i ) { + bool accepted = mAcceptedPatterns.empty(); + for ( const auto& pattern : mAcceptedPatterns ) { + if ( pattern.matches( files[i] ) ) { + accepted = true; + break; } } - } else { - getDirectoryFiles( mFiles, mNames, mPath, info, false, mIgnoreMatcher, - mAllowedMatcher.get(), mDisallowedMatcher.get() ); + if ( accepted && std::find( mFiles.begin(), mFiles.end(), files[i] ) == mFiles.end() ) { + mFiles.emplace_back( std::move( files[i] ) ); + mNames.emplace_back( std::move( names[i] ) ); + } } } else { tryAddFile( file ); diff --git a/src/tools/ecode/projectdirectorytree.hpp b/src/tools/ecode/projectdirectorytree.hpp index 56a8acf9c..c560f5db6 100644 --- a/src/tools/ecode/projectdirectorytree.hpp +++ b/src/tools/ecode/projectdirectorytree.hpp @@ -193,7 +193,8 @@ class ProjectDirectoryTree { void getDirectoryFiles( std::vector& files, std::vector& names, std::string directory, std::set currentDirs, const bool& ignoreHidden, IgnoreMatcherManager& ignoreMatcher, - GitIgnoreMatcher* allowedMatcher, GitIgnoreMatcher* disallowedMatcher ); + GitIgnoreMatcher* allowedMatcher, GitIgnoreMatcher* disallowedMatcher, + bool initialScan = true ); void addFile( const FileInfo& file );