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; 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 (!_running)
break;
if (!ec)
{
if (boost::filesystem::is_regular(path) && isFileSupported(path, _fileExtensions)) if (boost::filesystem::is_regular(path) && isFileSupported(path, _fileExtensions))
stats.totalFiles++; 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; 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))
{ {