Made early exit a bit faster
This commit is contained in:
@@ -78,7 +78,7 @@ getLastWriteTime(const std::filesystem::path& file)
|
||||
return Wt::WDateTime::fromTime_t(sb.st_mtime);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool(std::error_code, const std::filesystem::path&)> cb)
|
||||
{
|
||||
std::error_code ec;
|
||||
@@ -87,7 +87,7 @@ exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool
|
||||
if (ec)
|
||||
{
|
||||
cb(ec, directory);
|
||||
return;
|
||||
return true; // try to continue exploring anyway
|
||||
}
|
||||
|
||||
std::filesystem::directory_iterator itEnd;
|
||||
@@ -108,16 +108,18 @@ exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool
|
||||
else if (std::filesystem::is_directory(*itPath, ec))
|
||||
{
|
||||
if (!ec)
|
||||
exploreFilesRecursive(*itPath, cb);
|
||||
continueExploring = exploreFilesRecursive(*itPath, cb);
|
||||
else
|
||||
continueExploring = cb(ec, *itPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (!continueExploring)
|
||||
break;
|
||||
return false;
|
||||
|
||||
itPath.increment(ec);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ bool ensureDirectory(const std::filesystem::path& dir);
|
||||
// Get the last write time since Epoch
|
||||
Wt::WDateTime getLastWriteTime(const std::filesystem::path& dir);
|
||||
|
||||
void exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool(std::error_code, const std::filesystem::path&)> cb);
|
||||
// returns false if aborted by user
|
||||
bool exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool(std::error_code, const std::filesystem::path&)> cb);
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user