aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--src/support/filesystem_context.cc29
-rw-r--r--test/read_directory/reference.xml6
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>