Scanner: correctly skip files when an error occurs

This commit is contained in:
emeric
2019-08-08 13:24:46 +02:00
parent b87dd2b97a
commit 35b9b86df5
+14 -15
View File
@@ -331,7 +331,7 @@ MediaScanner::countAllFiles(Stats& stats)
stats.totalFiles = 0; stats.totalFiles = 0;
boost::filesystem::recursive_directory_iterator itPath(_mediaDirectory, ec); boost::filesystem::recursive_directory_iterator itPath {_mediaDirectory, ec};
if (ec) if (ec)
{ {
LMS_LOG(DBUPDATER, ERROR) << "Cannot iterate over '" << _mediaDirectory.string() << "': " << ec.message(); LMS_LOG(DBUPDATER, ERROR) << "Cannot iterate over '" << _mediaDirectory.string() << "': " << ec.message();
@@ -339,18 +339,20 @@ MediaScanner::countAllFiles(Stats& stats)
} }
boost::filesystem::recursive_directory_iterator itEnd; boost::filesystem::recursive_directory_iterator itEnd;
while (itPath != itEnd && _running) while (_running && itPath != itEnd)
{ {
if (stats.totalFiles % 250 == 0) const boost::filesystem::path& path {*itPath};
notifyInProgressIfNeeded(stats);
const boost::filesystem::path& path {*itPath++}; if (!ec)
{
if (boost::filesystem::is_regular(path) && isFileSupported(path, _fileExtensions))
stats.totalFiles++;
if (!_running) if (stats.totalFiles % 250 == 0)
break; notifyInProgressIfNeeded(stats);
}
if (boost::filesystem::is_regular(path) && isFileSupported(path, _fileExtensions)) itPath.increment(ec);
stats.totalFiles++;
} }
} }
@@ -639,7 +641,7 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
track.modify()->setCopyrightURL(trackInfo->copyrightURL); track.modify()->setCopyrightURL(trackInfo->copyrightURL);
} }
void void
MediaScanner::scanMediaDirectory(boost::filesystem::path mediaDirectory, bool forceScan, Stats& stats) MediaScanner::scanMediaDirectory(boost::filesystem::path mediaDirectory, bool forceScan, Stats& stats)
{ {
boost::system::error_code ec; boost::system::error_code ec;
@@ -652,16 +654,13 @@ MediaScanner::scanMediaDirectory(boost::filesystem::path mediaDirectory, bool fo
} }
boost::filesystem::recursive_directory_iterator itEnd; boost::filesystem::recursive_directory_iterator itEnd;
while (itPath != itEnd) while (_running && itPath != itEnd)
{ {
const boost::filesystem::path& path {*itPath}; const boost::filesystem::path& path {*itPath};
if (!_running)
return;
if (ec) if (ec)
{ {
LMS_LOG(DBUPDATER, ERROR) << "Cannot process entry: " << ec.message(); LMS_LOG(DBUPDATER, ERROR) << "Cannot process entry '" << path.string() << "': " << ec.message();
} }
else if (boost::filesystem::is_regular(path)) else if (boost::filesystem::is_regular(path))
{ {