move empty pattern check into while loop (#81)

This commit is contained in:
Pheenoh 2024-08-19 21:00:15 -06:00 committed by GitHub
parent bcc6eae470
commit 93862405ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 7 deletions

View File

@ -701,16 +701,10 @@ namespace kernel32 {
return false; return false;
} }
// If pattern is empty, just iterate
if (handle->pattern.empty()) {
handle->it++;
return handle->it != std::filesystem::directory_iterator();
}
// Look for a matching file with the pattern // Look for a matching file with the pattern
while (handle->it != std::filesystem::directory_iterator()) { while (handle->it != std::filesystem::directory_iterator()) {
std::filesystem::path path = *handle->it; std::filesystem::path path = *handle->it;
if (fnmatch(handle->pattern.c_str(), path.filename().c_str(), 0) == 0) { if (!handle->pattern.empty() && fnmatch(handle->pattern.c_str(), path.filename().c_str(), 0) == 0) {
return true; return true;
} }
handle->it++; handle->it++;