@@ -11,55 +11,49 @@ namespace fs = std::filesystem;
11
11
* @return a list of paths to the files found
12
12
*/
13
13
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
15
15
{
16
16
std::vector<fs::path> result;
17
-
18
17
if (!fs::exists (directory) || !fs::is_directory (directory)) {
19
18
return result;
20
19
}
21
20
22
21
// Normalize ignore directories into absolute canonical paths
23
22
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));
32
29
}
33
30
}
34
31
35
32
fs::recursive_directory_iterator it (directory);
36
33
fs::recursive_directory_iterator end;
34
+
37
35
while (it != end) {
36
+ const fs::directory_entry& entry = *it;
38
37
39
- if (const fs::directory_entry& entry = *it; entry .is_directory () && ignorePaths.empty ()) {
38
+ if (entry.is_directory () && ! ignorePaths.empty ()) {
40
39
fs::path current = fs::weakly_canonical (entry.path ());
41
-
42
40
// Skip if inside any ignored directory
43
41
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
+ });
48
45
if (skip) {
49
- it.disable_recursion_pending (); // skip this whole subtree
46
+ it.disable_recursion_pending ();
50
47
}
51
- }
48
+ }
52
49
else if (entry.is_regular_file ()) {
53
50
std::string ext = entry.path ().extension ().string ();
54
-
55
51
if (std::find (extensions.begin (), extensions.end (), ext) != extensions.end ()) {
56
52
result.push_back (entry.path ());
57
53
}
58
54
}
59
-
60
55
++it;
61
56
}
62
-
63
57
return result;
64
58
}
65
59
0 commit comments