Attempt to properly scan all the files during scan

This commit is contained in:
emeric
2020-02-20 13:32:48 +01:00
parent 428ab70d27
commit 284231ff92
7 changed files with 59 additions and 68 deletions
+36
View File
@@ -87,3 +87,39 @@ getLastWriteTime(const std::filesystem::path& file)
return Wt::WDateTime::fromTime_t(sb.st_mtime);
}
void
exploreFilesRecursive(const std::filesystem::path& directory, std::function<void(std::error_code, const std::filesystem::path&)> cb)
{
std::error_code ec;
std::filesystem::directory_iterator itPath {directory, std::filesystem::directory_options::follow_directory_symlink, ec};
if (ec)
{
cb(ec, directory);
return;
}
std::filesystem::directory_iterator itEnd;
while (itPath != itEnd)
{
if (ec)
{
cb(ec, *itPath);
}
else
{
if (std::filesystem::is_regular_file(*itPath, ec))
cb(ec, *itPath);
else if (std::filesystem::is_directory(*itPath, ec))
{
if (!ec)
exploreFilesRecursive(*itPath, cb);
else
cb(ec, *itPath);
}
}
itPath.increment(ec);
}
}
+7 -3
View File
@@ -20,6 +20,7 @@
#pragma once
#include <filesystem>
#include <functional>
#include <string>
#include <vector>
@@ -34,10 +35,13 @@ bool ensureDirectory(const std::filesystem::path& dir);
// Get the last write time since Epoch
Wt::WDateTime getLastWriteTime(const std::filesystem::path& dir);
namespace std {
void exploreFilesRecursive(const std::filesystem::path& directory, std::function<void(std::error_code, const std::filesystem::path&)> cb);
namespace std
{
template <>
struct hash<std::filesystem::path> {
struct hash<std::filesystem::path>
{
inline std::size_t operator()(const std::filesystem::path &path) const { return hash_value(path); }
};
}