aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-13 16:30:58 +0200
committerAdrian Kummerländer2014-05-13 16:30:58 +0200
commitb3bf487144a1a2978cc17d40b6d6ba1c0467fc37 (patch)
tree391b1a4a23ed5ec82ab0bd1032106f43df349e09 /src
parentc4fcfa9b39d9c29ecbc3ac1c12b7e5b2beb24a6d (diff)
downloadInputXSLT-b3bf487144a1a2978cc17d40b6d6ba1c0467fc37.tar
InputXSLT-b3bf487144a1a2978cc17d40b6d6ba1c0467fc37.tar.gz
InputXSLT-b3bf487144a1a2978cc17d40b6d6ba1c0467fc37.tar.bz2
InputXSLT-b3bf487144a1a2978cc17d40b6d6ba1c0467fc37.tar.lz
InputXSLT-b3bf487144a1a2978cc17d40b6d6ba1c0467fc37.tar.xz
InputXSLT-b3bf487144a1a2978cc17d40b6d6ba1c0467fc37.tar.zst
InputXSLT-b3bf487144a1a2978cc17d40b6d6ba1c0467fc37.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/support/filesystem_context.cc29
1 files changed, 21 insertions, 8 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);
}
}