From b3bf487144a1a2978cc17d40b6d6ba1c0467fc37 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Tue, 13 May 2014 16:30:58 +0200 Subject: Sorting FilesystemContext iteration results * order of items in a directory was varying across platforms which hindered testability * they are now temporarily copied into a std::vector instance and then sorted using std::sort * updated "read_directory" test case reference file accordingly --- src/support/filesystem_context.cc | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src') 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 +#include + #include "support/xerces_string_guard.h" namespace { @@ -42,15 +45,25 @@ void FilesystemContext::iterate( const boost::filesystem::path& directory, std::function 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 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); } } -- cgit v1.2.3