diff options
-rw-r--r-- | src/support/filesystem_context.cc | 29 | ||||
-rw-r--r-- | test/read_directory/reference.xml | 6 |
2 files changed, 24 insertions, 11 deletions
diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc index 6ddbf7a..30502b3 100644 --- a/src/support/filesystem_context.cc +++ b/src/support/filesystem_context.cc @@ -1,5 +1,8 @@ #include "filesystem_context.h" +#include <algorithm> +#include <iterator> + #include "support/xerces_string_guard.h" namespace { @@ -42,15 +45,25 @@ void FilesystemContext::iterate( const boost::filesystem::path& directory, std::function<void(const boost::filesystem::path&)> func ) const { - if ( boost::filesystem::is_directory(directory) ) { - for ( boost::filesystem::directory_iterator iter(directory); - iter != boost::filesystem::directory_iterator(); - ++iter ) { - if ( boost::filesystem::is_regular_file(iter->status()) || - boost::filesystem::is_directory(iter->status()) ) { - func(*iter); - } + std::vector<boost::filesystem::path> directoryItems; + + std::copy_if( + boost::filesystem::directory_iterator(directory), + boost::filesystem::directory_iterator(), + std::back_inserter(directoryItems), + [](const boost::filesystem::path& p) -> bool { + return boost::filesystem::is_regular_file(p) || + boost::filesystem::is_directory(p); } + ); + + std::sort( + directoryItems.begin(), + directoryItems.end() + ); + + for ( auto&& item : directoryItems ) { + func(item); } } diff --git a/test/read_directory/reference.xml b/test/read_directory/reference.xml index fedd903..8252569 100644 --- a/test/read_directory/reference.xml +++ b/test/read_directory/reference.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <test_case> <function_read_directory> -<item>read_directory</item> -<item>read_xml_file</item> <item>common</item> +<item>default_params</item> +<item>read_directory</item> <item>read_file</item> +<item>read_xml_file</item> <item>transform</item> -<item>default_params</item> </function_read_directory> </test_case> |