mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-30 14:53:11 +00:00
Adopt dir_iter_t in descend_unique_hierarchy
Migrate this function from wreaddir_resolving to dir_iter_t
This commit is contained in:
parent
2a9366f938
commit
749d71288d
1 changed files with 17 additions and 20 deletions
|
@ -586,42 +586,39 @@ class wildcard_expander_t {
|
||||||
wcstring unique_hierarchy;
|
wcstring unique_hierarchy;
|
||||||
wcstring abs_unique_hierarchy = start_point;
|
wcstring abs_unique_hierarchy = start_point;
|
||||||
|
|
||||||
bool stop_descent = false;
|
for (;;) {
|
||||||
DIR *dir;
|
|
||||||
while (!stop_descent && (dir = wopendir(abs_unique_hierarchy))) {
|
|
||||||
// We keep track of the single unique_entry entry. If we get more than one, it's not
|
// We keep track of the single unique_entry entry. If we get more than one, it's not
|
||||||
// unique and we stop the descent.
|
// unique and we stop the descent.
|
||||||
wcstring unique_entry;
|
wcstring unique_entry;
|
||||||
|
dir_iter_t dir(abs_unique_hierarchy);
|
||||||
bool child_is_dir;
|
if (!dir.valid()) {
|
||||||
wcstring child_entry;
|
break;
|
||||||
while (wreaddir_resolving(dir, abs_unique_hierarchy, child_entry, &child_is_dir)) {
|
}
|
||||||
if (child_entry.empty() || child_entry.at(0) == L'.') {
|
while (const auto *entry = dir.next()) {
|
||||||
|
if (entry->name.empty() || entry->name.at(0) == L'.') {
|
||||||
continue; // either hidden, or . and .. entries -- skip them
|
continue; // either hidden, or . and .. entries -- skip them
|
||||||
} else if (child_is_dir && unique_entry.empty()) {
|
}
|
||||||
unique_entry = child_entry; // first candidate
|
if (entry->is_dir() && unique_entry.empty()) {
|
||||||
|
unique_entry = entry->name; // first candidate
|
||||||
} else {
|
} else {
|
||||||
// We either have two or more candidates, or the child is not a directory. We're
|
// We either have two or more candidates, or the child is not a directory. We're
|
||||||
// done.
|
// done.
|
||||||
stop_descent = true;
|
unique_entry.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We stop if we got two or more entries; also stop if we got zero or were interrupted
|
// We stop if we got two or more entries; also stop if we got zero or were interrupted
|
||||||
if (unique_entry.empty() || interrupted_or_overflowed()) {
|
if (unique_entry.empty() || interrupted_or_overflowed()) {
|
||||||
stop_descent = true;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stop_descent) {
|
// We have an entry in the unique hierarchy!
|
||||||
// We have an entry in the unique hierarchy!
|
append_path_component(unique_hierarchy, unique_entry);
|
||||||
append_path_component(unique_hierarchy, unique_entry);
|
unique_hierarchy.push_back(L'/');
|
||||||
unique_hierarchy.push_back(L'/');
|
|
||||||
|
|
||||||
append_path_component(abs_unique_hierarchy, unique_entry);
|
append_path_component(abs_unique_hierarchy, unique_entry);
|
||||||
abs_unique_hierarchy.push_back(L'/');
|
abs_unique_hierarchy.push_back(L'/');
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
}
|
}
|
||||||
return unique_hierarchy;
|
return unique_hierarchy;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue