Skip to content

Commit 710428a

Browse files
authored
Merge pull request #15 from jm6271/fix/ignore
Fix bug in ignore system
2 parents 8c6794e + b1e7b8f commit 710428a

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

loc/DirectoryScanner.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,49 @@ namespace fs = std::filesystem;
1111
* @return a list of paths to the files found
1212
*/
1313
std::vector<fs::path> DirectoryScanner::Scan(const fs::path& directory, const std::vector<std::string>& extensions,
14-
const std::vector<fs::path>& ignoreDirs) const
14+
const std::vector<fs::path>& ignoreDirs) const
1515
{
1616
std::vector<fs::path> result;
17-
1817
if (!fs::exists(directory) || !fs::is_directory(directory)) {
1918
return result;
2019
}
2120

2221
// Normalize ignore directories into absolute canonical paths
2322
std::vector<fs::path> ignorePaths;
24-
if (!ignoreDirs.empty())
25-
{
26-
for (const auto& dir : ignoreDirs) {
27-
if (dir.is_absolute()) {
28-
ignorePaths.push_back(fs::weakly_canonical(dir));
29-
} else {
30-
ignorePaths.push_back(fs::weakly_canonical(directory / dir));
31-
}
23+
for (const auto& dir : ignoreDirs) {
24+
if (dir.is_absolute()) {
25+
ignorePaths.push_back(fs::weakly_canonical(dir));
26+
}
27+
else {
28+
ignorePaths.push_back(fs::weakly_canonical(directory / dir));
3229
}
3330
}
3431

3532
fs::recursive_directory_iterator it(directory);
3633
fs::recursive_directory_iterator end;
34+
3735
while (it != end) {
36+
const fs::directory_entry& entry = *it;
3837

39-
if (const fs::directory_entry& entry = *it; entry.is_directory() && ignorePaths.empty()) {
38+
if (entry.is_directory() && !ignorePaths.empty()) {
4039
fs::path current = fs::weakly_canonical(entry.path());
41-
4240
// Skip if inside any ignored directory
4341
bool skip = std::any_of(ignorePaths.begin(), ignorePaths.end(),
44-
[&](const fs::path& ignore) {
45-
return isSubPath(ignore, current);
46-
});
47-
42+
[&](const fs::path& ignore) {
43+
return isSubPath(ignore, current);
44+
});
4845
if (skip) {
49-
it.disable_recursion_pending(); // skip this whole subtree
46+
it.disable_recursion_pending();
5047
}
51-
}
48+
}
5249
else if (entry.is_regular_file()) {
5350
std::string ext = entry.path().extension().string();
54-
5551
if (std::find(extensions.begin(), extensions.end(), ext) != extensions.end()) {
5652
result.push_back(entry.path());
5753
}
5854
}
59-
6055
++it;
6156
}
62-
6357
return result;
6458
}
6559

0 commit comments

Comments
 (0)