Restored cancellable scan

This commit is contained in:
emeric
2020-02-20 14:09:52 +01:00
parent 284231ff92
commit 0ad4973a5a
3 changed files with 23 additions and 12 deletions
+11 -7
View File
@@ -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);
+11 -4
View File
@@ -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);
}
}
+1 -1
View File
@@ -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
{