@@ -29,10 +29,15 @@ using namespace o2::event_visualisation;
2929deque<string> DirectoryLoader::load (const std::string& path, const std::string& marker, const std::vector<std::string>& ext)
3030{
3131 deque<string> result;
32- for (const auto & entry : std::filesystem::directory_iterator (path)) {
33- if (std::find (ext.begin (), ext.end (), entry.path ().extension ()) != ext.end ()) {
34- result.push_back (entry.path ().filename ());
32+ try {
33+ for (const auto & entry : std::filesystem::directory_iterator (path)) {
34+ if (std::find (ext.begin (), ext.end (), entry.path ().extension ()) != ext.end ()) {
35+ result.push_back (entry.path ().filename ());
36+ }
3537 }
38+ } catch (std::filesystem::filesystem_error const & ex) {
39+ LOGF (error, " filesystem problem during DirectoryLoader::load: %s" , ex.what ());
40+ return result;
3641 }
3742 // comparison with safety if marker not in the filename (-1+1 gives 0)
3843 std::sort (result.begin (), result.end (),
@@ -56,7 +61,8 @@ bool DirectoryLoader::canCreateNextFile(const std::vector<std::string>& paths, c
5661 }
5762 }
5863 } catch (std::filesystem::filesystem_error const & ex) {
59- LOGF (info, " filesystem problem: %s" , ex.what ());
64+ LOGF (error, " filesystem problem during DirectoryLoader::canCreateNextFile: %s" , ex.what ());
65+ return false ;
6066 }
6167 }
6268
@@ -87,12 +93,17 @@ bool DirectoryLoader::canCreateNextFile(const std::vector<std::string>& paths, c
8793deque<string> DirectoryLoader::load (const std::vector<std::string>& paths, const std::string& marker, const std::vector<std::string>& ext)
8894{
8995 deque<string> result;
90- for (const auto & path : paths) {
91- for (const auto & entry : std::filesystem::directory_iterator (path)) {
92- if (std::find (ext.begin (), ext.end (), entry.path ().extension ()) != ext.end ()) {
93- result.push_back (entry.path ().filename ());
96+ try {
97+ for (const auto & path : paths) {
98+ for (const auto & entry : std::filesystem::directory_iterator (path)) {
99+ if (std::find (ext.begin (), ext.end (), entry.path ().extension ()) != ext.end ()) {
100+ result.push_back (entry.path ().filename ());
101+ }
94102 }
95103 }
104+ } catch (std::filesystem::filesystem_error const & ex) {
105+ LOGF (error, " filesystem problem during DirectoryLoader::load: %s" , ex.what ());
106+ return result;
96107 }
97108 // comparison with safety if marker not in the filename (-1+1 gives 0)
98109 std::sort (result.begin (), result.end (),
@@ -135,10 +146,14 @@ std::time_t to_time_t(TP tp)
135146int DirectoryLoader::getNumberOfFiles (const std::string& path, std::vector<std::string>& ext)
136147{
137148 int res = 0 ;
138- for (const auto & entry : std::filesystem::directory_iterator (path)) {
139- if (std::find (ext.begin (), ext.end (), entry.path ().extension ()) != ext.end ()) {
140- res++;
149+ try {
150+ for (const auto & entry : std::filesystem::directory_iterator (path)) {
151+ if (std::find (ext.begin (), ext.end (), entry.path ().extension ()) != ext.end ()) {
152+ res++;
153+ }
141154 }
155+ } catch (std::filesystem::filesystem_error const & ex) {
156+ LOGF (error, " filesystem problem during DirectoryLoader::getNumberOfFiles: %s" , ex.what ());
142157 }
143158 return res;
144159}
@@ -160,8 +175,12 @@ std::string DirectoryLoader::getLatestFile(const std::string& path, std::vector<
160175
161176void DirectoryLoader::removeOldestFiles (const std::string& path, std::vector<std::string>& ext, const int remaining)
162177{
163- while (getNumberOfFiles (path, ext) > remaining) {
164- LOGF (info, " removing oldest file in folder: %s : %s" , path, getLatestFile (path, ext));
165- filesystem::remove (path + " /" + getLatestFile (path, ext));
178+ try {
179+ while (getNumberOfFiles (path, ext) > remaining) {
180+ LOGF (info, " removing oldest file in folder: %s : %s" , path, getLatestFile (path, ext));
181+ filesystem::remove (path + " /" + getLatestFile (path, ext));
182+ }
183+ } catch (std::filesystem::filesystem_error const & ex) {
184+ LOGF (error, " filesystem problem during DirectoryLoader::removeOldestFiles: %s" , ex.what ());
166185 }
167186}
0 commit comments