summaryrefslogtreecommitdiff
path: root/src/textual.cc
diff options
context:
space:
mode:
authorEmin Martinian <emin.martinian@gmail.com>2020-07-31 23:22:19 -0400
committerJohn Wiegley <johnw@newartisans.com>2020-08-13 22:33:51 -0700
commit8e55ba6929d1365e3f3f9441adcc94c92bc35330 (patch)
tree6aab47815e1b73b6bfaf918a329d18cc742725fb /src/textual.cc
parentca780a5cc0f922b94705270baeda3343f369d438 (diff)
downloadfork-ledger-8e55ba6929d1365e3f3f9441adcc94c92bc35330.tar.gz
fork-ledger-8e55ba6929d1365e3f3f9441adcc94c92bc35330.tar.bz2
fork-ledger-8e55ba6929d1365e3f3f9441adcc94c92bc35330.zip
Make it so that the include directive sorts when using wildcards.
Before this commit, doing something like 'include data/*.dat' would produce undesired behaviour because the matches for 'data/*.dat' would not be sorted correctly. See https://github.com/ledger/ledger/issues/1659 for details.
Diffstat (limited to 'src/textual.cc')
-rw-r--r--src/textual.cc16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/textual.cc b/src/textual.cc
index c3bb2c2f..a629048f 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -40,6 +40,7 @@
#include "query.h"
#include "pstream.h"
#include "pool.h"
+#include <algorithm>
#if HAVE_BOOST_PYTHON
#include "pyinterp.h"
#endif
@@ -751,12 +752,19 @@ void instance_t::include_directive(char * line)
bool files_found = false;
if (exists(parent_path)) {
filesystem::directory_iterator end;
- for (filesystem::directory_iterator iter(parent_path);
- iter != end;
- ++iter) {
+
+ // Sort parent_path since on some file systems it is unsorted.
+ std::vector<path> sorted_parent_path;
+ std::copy(filesystem::directory_iterator(parent_path),
+ filesystem::directory_iterator(),
+ std::back_inserter(sorted_parent_path));
+ std::sort(sorted_parent_path.begin(), sorted_parent_path.end());
+
+ for (std::vector<path>::const_iterator iter(sorted_parent_path.begin()),
+ it_end(sorted_parent_path.end()); iter != it_end; ++iter) {
if (is_regular_file(*iter))
{
- string base = (*iter).path().filename().string();
+ string base = (*iter).filename().string();
if (glob.match(base)) {
journal_t * journal = context.journal;
account_t * master = top_account();