Commit b8d0765f authored by Kenton Varda's avatar Kenton Varda

kj::Directory::list*() should return sorted lists to avoid non-determinism.

parent 7185b54a
......@@ -34,6 +34,7 @@
#include <stdlib.h>
#include "vector.h"
#include "miniposix.h"
#include <algorithm>
#if __linux__
#include <linux/fs.h>
......@@ -599,7 +600,8 @@ public:
}
KJ_DEFER(closedir(dir));
kj::Vector<Decay<decltype(func(instance<StringPtr>(), instance<FsNode::Type>()))>> entries;
typedef Decay<decltype(func(instance<StringPtr>(), instance<FsNode::Type>()))> Entry;
kj::Vector<Entry> entries;
for (;;) {
errno = 0;
......@@ -634,7 +636,9 @@ public:
}
}
return entries.releaseAsArray();
auto result = entries.releaseAsArray();
std::sort(result.begin(), result.end());
return result;
}
Array<String> listNames() {
......
......@@ -1287,7 +1287,11 @@ private:
};
Clock& clock;
std::map<StringPtr, EntryImpl> entries;
// Note: If this changes to a non-sorted map, listNames() and listEntries() must be updated to
// sort their results.
Date lastModified;
template <typename T>
......
......@@ -426,6 +426,12 @@ public:
struct Entry {
FsNode::Type type;
String name;
inline bool operator< (const Entry& other) const { return name < other.name; }
inline bool operator> (const Entry& other) const { return name > other.name; }
inline bool operator<=(const Entry& other) const { return name <= other.name; }
inline bool operator>=(const Entry& other) const { return name >= other.name; }
// Convenience comparison operators to sort entries by name.
};
virtual Array<Entry> listEntries() = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment