From 6fa1ba1300416a2a8a81f388b28418302d32fa08 Mon Sep 17 00:00:00 2001 From: emeric Date: Tue, 11 Aug 2015 13:53:49 +0200 Subject: [PATCH] [DB] Catch permission file errors when updating --- src/database-updater/DatabaseUpdater.cpp | 65 ++++++++++++++---------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/database-updater/DatabaseUpdater.cpp b/src/database-updater/DatabaseUpdater.cpp index 2239d96c..5dc2af7a 100644 --- a/src/database-updater/DatabaseUpdater.cpp +++ b/src/database-updater/DatabaseUpdater.cpp @@ -589,44 +589,53 @@ Updater::processDirectory(const boost::filesystem::path& rootDirectory, bool Updater::checkFile(const boost::filesystem::path& p, const std::vector& rootDirs, const std::vector& extensions) { - bool status = true; + try + { + bool status = true; - // For each track, make sure the the file still exists - // and still belongs to a root directory - if (!boost::filesystem::exists( p ) - || !boost::filesystem::is_regular( p ) ) - { - LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Missing file '" << p << "'"; - status = false; - } - else - { - bool foundRoot = false; - BOOST_FOREACH(const boost::filesystem::path& rootDir, rootDirs) + // For each track, make sure the the file still exists + // and still belongs to a root directory + if (!boost::filesystem::exists( p ) + || !boost::filesystem::is_regular( p ) ) { - if (p.string().find( rootDir.string() ) != std::string::npos) + LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Missing file '" << p << "'"; + status = false; + } + else + { + bool foundRoot = false; + BOOST_FOREACH(const boost::filesystem::path& rootDir, rootDirs) { - foundRoot = true; - break; + if (p.string().find( rootDir.string() ) != std::string::npos) + { + foundRoot = true; + break; + } + } + + if (!foundRoot) + { + LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Out of root file '" << p << "'"; + status = false; + } + else if (!isFileSupported(p, extensions)) + { + LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "File format no longer supported for '" << p << "'"; + status = false; } } - if (!foundRoot) - { - LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Out of root file '" << p << "'"; - status = false; - } - else if (!isFileSupported(p, extensions)) - { - LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "File format no longer supported for '" << p << "'"; - status = false; - } + return status; + + } + catch (boost::filesystem::filesystem_error& e) + { + LMS_LOG(MOD_DBUPDATER, SEV_ERROR) << "Caught exception while checking file '" << p << "': " << e.what(); + return false; } - return status; } - void Updater::checkAudioFiles( Stats& stats ) {