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
+13 -14
View File
@@ -331,7 +331,7 @@ MediaScanner::countAllFiles(Stats& stats)
stats.totalFiles = 0;
boost::filesystem::recursive_directory_iterator itPath(_mediaDirectory, ec);
boost::filesystem::recursive_directory_iterator itPath {_mediaDirectory, ec};
if (ec)
{
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;
while (itPath != itEnd && _running)
while (_running && itPath != itEnd)
{
if (stats.totalFiles % 250 == 0)
notifyInProgressIfNeeded(stats);
const boost::filesystem::path& path {*itPath++};
if (!_running)
break;
const boost::filesystem::path& path {*itPath};
if (!ec)
{
if (boost::filesystem::is_regular(path) && isFileSupported(path, _fileExtensions))
stats.totalFiles++;
if (stats.totalFiles % 250 == 0)
notifyInProgressIfNeeded(stats);
}
itPath.increment(ec);
}
}
@@ -652,16 +654,13 @@ MediaScanner::scanMediaDirectory(boost::filesystem::path mediaDirectory, bool fo
}
boost::filesystem::recursive_directory_iterator itEnd;
while (itPath != itEnd)
while (_running && itPath != itEnd)
{
const boost::filesystem::path& path {*itPath};
if (!_running)
return;
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))
{