Restored cancellable scan
This commit is contained in:
@@ -354,16 +354,18 @@ MediaScanner::countAllFiles(ScanStats& stats)
|
||||
|
||||
exploreFilesRecursive(_mediaDirectory, [&](std::error_code ec, const std::filesystem::path& path)
|
||||
{
|
||||
if (ec)
|
||||
return;
|
||||
if (!_running)
|
||||
return false;
|
||||
|
||||
if (isFileSupported(path, _fileExtensions))
|
||||
if (!ec && isFileSupported(path, _fileExtensions))
|
||||
{
|
||||
stats.filesToScan++;
|
||||
|
||||
if (stats.filesToScan % 250 == 0)
|
||||
notifyInProgressIfNeeded(stats);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -736,20 +738,22 @@ MediaScanner::scanMediaDirectory(const std::filesystem::path& mediaDirectory, bo
|
||||
{
|
||||
exploreFilesRecursive(mediaDirectory, [&](std::error_code ec, const std::filesystem::path& path)
|
||||
{
|
||||
if (!_running)
|
||||
return false;
|
||||
|
||||
if (ec)
|
||||
{
|
||||
LMS_LOG(DBUPDATER, ERROR) << "Cannot process entry '" << path.string() << "': " << ec.message();
|
||||
stats.errors.emplace_back(ScanError {path, ScanErrorType::CannotReadFile, ec.message()});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isFileSupported(path, _fileExtensions))
|
||||
else if (isFileSupported(path, _fileExtensions))
|
||||
{
|
||||
scanAudioFile(path, forceScan, stats );
|
||||
|
||||
notifyInProgressIfNeeded(stats);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
notifyInProgress(stats);
|
||||
|
||||
@@ -88,7 +88,7 @@ getLastWriteTime(const std::filesystem::path& file)
|
||||
}
|
||||
|
||||
void
|
||||
exploreFilesRecursive(const std::filesystem::path& directory, std::function<void(std::error_code, const std::filesystem::path&)> cb)
|
||||
exploreFilesRecursive(const std::filesystem::path& directory, std::function<bool(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};
|
||||
@@ -102,23 +102,30 @@ exploreFilesRecursive(const std::filesystem::path& directory, std::function<void
|
||||
std::filesystem::directory_iterator itEnd;
|
||||
while (itPath != itEnd)
|
||||
{
|
||||
bool continueExploring {true};
|
||||
|
||||
if (ec)
|
||||
{
|
||||
cb(ec, *itPath);
|
||||
continueExploring = cb(ec, *itPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (std::filesystem::is_regular_file(*itPath, ec))
|
||||
cb(ec, *itPath);
|
||||
{
|
||||
continueExploring = cb(ec, *itPath);
|
||||
}
|
||||
else if (std::filesystem::is_directory(*itPath, ec))
|
||||
{
|
||||
if (!ec)
|
||||
exploreFilesRecursive(*itPath, cb);
|
||||
else
|
||||
cb(ec, *itPath);
|
||||
continueExploring = cb(ec, *itPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (!continueExploring)
|
||||
break;
|
||||
|
||||
itPath.increment(ec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ 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<void(std::error_code, const std::filesystem::path&)> cb);
|
||||
void 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