Moved scanner specific code from core
This commit is contained in:
@@ -35,63 +35,6 @@ namespace lms::core::pathUtils
|
||||
return std::filesystem::create_directory(dir);
|
||||
}
|
||||
|
||||
bool exploreFilesRecursive(const std::filesystem::path& directory, ExploreFileCallback cb, const std::filesystem::path* excludeDirFileName)
|
||||
{
|
||||
std::error_code ec;
|
||||
std::filesystem::directory_iterator itPath{ directory, std::filesystem::directory_options::follow_directory_symlink, ec };
|
||||
|
||||
if (ec)
|
||||
{
|
||||
cb(ec, directory, nullptr);
|
||||
return true; // try to continue exploring anyway
|
||||
}
|
||||
|
||||
if (excludeDirFileName && !excludeDirFileName->empty())
|
||||
{
|
||||
const std::filesystem::path excludePath{ directory / *excludeDirFileName };
|
||||
|
||||
if (std::filesystem::exists(excludePath, ec))
|
||||
{
|
||||
// TODO: handle exclude another way + remove this log
|
||||
LMS_LOG(DBUPDATER, DEBUG, "Found " << excludePath << ": skipping directory");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::filesystem::directory_iterator itEnd;
|
||||
while (itPath != itEnd)
|
||||
{
|
||||
bool continueExploring{ true };
|
||||
|
||||
if (ec)
|
||||
{
|
||||
continueExploring = cb(ec, *itPath, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::filesystem::directory_entry& entry{ *itPath };
|
||||
|
||||
if (entry.is_regular_file())
|
||||
{
|
||||
FileInfo fileInfo;
|
||||
fileInfo.fileSize = entry.file_size();
|
||||
fileInfo.lastWriteTime = Wt::WDateTime{ std::chrono::file_clock::to_sys(entry.last_write_time()) };
|
||||
|
||||
continueExploring = cb(ec, *itPath, &fileInfo);
|
||||
}
|
||||
else if (entry.is_directory())
|
||||
continueExploring = exploreFilesRecursive(*itPath, cb, excludeDirFileName);
|
||||
}
|
||||
|
||||
if (!continueExploring)
|
||||
return false;
|
||||
|
||||
itPath.increment(ec);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hasFileAnyExtension(const std::filesystem::path& file, std::span<const std::filesystem::path> supportedExtensions)
|
||||
{
|
||||
const std::filesystem::path extension{ stringUtils::stringToLower(file.extension().c_str()) };
|
||||
|
||||
@@ -20,9 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <span>
|
||||
#include <system_error>
|
||||
|
||||
#include <Wt/WDateTime.h>
|
||||
|
||||
@@ -32,15 +30,6 @@ namespace lms::core::pathUtils
|
||||
// Create it if needed
|
||||
bool ensureDirectory(const std::filesystem::path& dir);
|
||||
|
||||
struct FileInfo
|
||||
{
|
||||
Wt::WDateTime lastWriteTime; // Last write time of the file since Epoch
|
||||
std::uint64_t fileSize{}; // Size of the file in bytes
|
||||
};
|
||||
using ExploreFileCallback = std::function<bool(std::error_code, const std::filesystem::path&, const FileInfo* fileInfo)>;
|
||||
// returns false if aborted by user
|
||||
bool exploreFilesRecursive(const std::filesystem::path& directory, ExploreFileCallback cb, const std::filesystem::path* excludeDirFileName = {});
|
||||
|
||||
// Check if file's extension is one of provided extensions
|
||||
bool hasFileAnyExtension(const std::filesystem::path& file, std::span<const std::filesystem::path> extensions);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user