From 0ad4973a5a78cb11e36f2158944317287242e8e6 Mon Sep 17 00:00:00 2001 From: emeric Date: Thu, 20 Feb 2020 14:09:52 +0100 Subject: [PATCH] Restored cancellable scan --- src/libs/scanner/impl/MediaScanner.cpp | 18 +++++++++++------- src/libs/utils/impl/Path.cpp | 15 +++++++++++---- src/libs/utils/include/utils/Path.hpp | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/libs/scanner/impl/MediaScanner.cpp b/src/libs/scanner/impl/MediaScanner.cpp index a6d27213..9de04c5b 100644 --- a/src/libs/scanner/impl/MediaScanner.cpp +++ b/src/libs/scanner/impl/MediaScanner.cpp @@ -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); diff --git a/src/libs/utils/impl/Path.cpp b/src/libs/utils/impl/Path.cpp index 246215f1..0bfc807b 100644 --- a/src/libs/utils/impl/Path.cpp +++ b/src/libs/utils/impl/Path.cpp @@ -88,7 +88,7 @@ getLastWriteTime(const std::filesystem::path& file) } void -exploreFilesRecursive(const std::filesystem::path& directory, std::function cb) +exploreFilesRecursive(const std::filesystem::path& directory, std::function 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 cb); +void exploreFilesRecursive(const std::filesystem::path& directory, std::function cb); namespace std {