From c6ecea564c6364deefb97b113f8b62b282f0feb3 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 3 Dec 2022 13:13:00 -0800 Subject: [PATCH] Fix issues that may incorrectly interupt directory traversal. --- src/musikcore/library/Indexer.cpp | 39 +++++++++++--------- src/musikcube/app/model/DirectoryAdapter.cpp | 26 +++++++++---- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/musikcore/library/Indexer.cpp b/src/musikcore/library/Indexer.cpp index abee59817..44639d54f 100644 --- a/src/musikcore/library/Indexer.cpp +++ b/src/musikcore/library/Indexer.cpp @@ -465,10 +465,8 @@ void Indexer::SyncDirectory( /* start recursive filesystem scan */ - try { /* boost::filesystem may throw */ - + try { /* for each file in the current path... */ - boost::filesystem::path path(currentPath); boost::filesystem::directory_iterator end; boost::filesystem::directory_iterator file(path); @@ -486,28 +484,33 @@ void Indexer::SyncDirectory( this->SyncDirectory(io, syncRoot, file->path().string(), pathId); } else { - std::string extension = file->path().extension().string(); - for (auto it : this->tagReaders) { - if (it->CanRead(extension.c_str())) { - if (io) { - io->post(boost::bind( - &Indexer::ReadMetadataFromFile, - this, - io, - file->path(), - pathIdStr)); + try { + std::string extension = file->path().extension().string(); + for (auto it : this->tagReaders) { + if (it->CanRead(extension.c_str())) { + if (io) { + io->post(boost::bind( + &Indexer::ReadMetadataFromFile, + this, + io, + file->path(), + pathIdStr)); + } + else { + this->ReadMetadataFromFile(nullptr, file->path(), pathIdStr); + } + break; } - else { - this->ReadMetadataFromFile(nullptr, file->path(), pathIdStr); - } - break; } } - + catch (...) { + /* boost::filesystem may throw trying to stat the file */ + } } } } catch(...) { + /* boost::filesystem may throw trying to open the directory */ } } diff --git a/src/musikcube/app/model/DirectoryAdapter.cpp b/src/musikcube/app/model/DirectoryAdapter.cpp index a99241e79..a361d26ae 100755 --- a/src/musikcube/app/model/DirectoryAdapter.cpp +++ b/src/musikcube/app/model/DirectoryAdapter.cpp @@ -76,15 +76,21 @@ static bool hasSubdirectories( directory_iterator file(p); while (file != end) { - if (is_directory(file->status())) { - if (showDotfiles || file->path().leaf().string()[0] != '.') { - return true; + try { + if (is_directory(file->status())) { + if (showDotfiles || file->path().leaf().string()[0] != '.') { + return true; + } } } + catch (...) { + /* may throw trying to stat the file */ + } ++file; } } catch (...) { + /* may throw trying to open the dir */ } return false; @@ -102,16 +108,22 @@ static void buildDirectoryList( directory_iterator file(p); while (file != end) { - if (is_directory(file->status())) { - std::string leaf = file->path().leaf().string(); - if (showDotfiles || leaf[0] != '.') { - target.push_back(leaf); + try { + if (is_directory(file->status())) { + std::string leaf = file->path().leaf().string(); + if (showDotfiles || leaf[0] != '.') { + target.push_back(leaf); + } } } + catch (...) { + /* may throw trying to stat the file */ + } ++file; } } catch (...) { + /* may throw trying to open the directory */ } try {