From 781b6e65053cd1bd703ee1f254d93bc13648e21d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 11 Sep 2009 15:05:34 +0200 Subject: StorageBackendFile: Don't crash if a type doesn't exist --- .../StorageBackendFile/StorageBackendFile.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/modules/StorageBackendFile') diff --git a/src/modules/StorageBackendFile/StorageBackendFile.cpp b/src/modules/StorageBackendFile/StorageBackendFile.cpp index 54d74ad..7c952bd 100644 --- a/src/modules/StorageBackendFile/StorageBackendFile.cpp +++ b/src/modules/StorageBackendFile/StorageBackendFile.cpp @@ -79,12 +79,15 @@ std::set StorageBackendFile::listTypes() throw (Core::Exception) { std::set ret; - for(boost::filesystem::directory_iterator it(storageRoot); it != boost::filesystem::directory_iterator(); ++it) { - boost::filesystem::path path = *it; + try { + for(boost::filesystem::directory_iterator it(storageRoot); it != boost::filesystem::directory_iterator(); ++it) { + boost::filesystem::path path = *it; - if(boost::filesystem::is_directory(path)) - ret.insert(path.filename()); + if(boost::filesystem::is_directory(path)) + ret.insert(path.filename()); + } } + catch(...) {} // Don't throw if we can't iterate over the dirs return ret; } @@ -100,12 +103,15 @@ std::set StorageBackendFile::list(const std::string &type) throw (C boost::filesystem::path path(storageRoot); path /= type; - for(boost::filesystem::directory_iterator it(path); it != boost::filesystem::directory_iterator(); ++it) { - boost::filesystem::path filePath = *it; + try { + for(boost::filesystem::directory_iterator it(path); it != boost::filesystem::directory_iterator(); ++it) { + boost::filesystem::path filePath = *it; - if(boost::filesystem::is_regular_file(filePath) && filePath.extension() == ".xml") - ret.insert(filePath.replace_extension().filename()); + if(boost::filesystem::is_regular_file(filePath) && filePath.extension() == ".xml") + ret.insert(filePath.replace_extension().filename()); + } } + catch(...) {} // Don't throw if we can't iterate over the dirs return ret; } -- cgit v1.2.3