From 1dfac0a8b9b3e53560ef14ae3167c8c1973088f0 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sat, 13 Oct 2012 12:29:04 +0200 Subject: [PATCH] Avoid randomness when processing directories. Order of files in file system order is random (maybe different for every user). Determinsm is good, i.e. when loading Nasal scripts in a fixed, known sequence, or config files, where the later may overrule settings of the earlier. --- simgear/misc/sg_dir.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/simgear/misc/sg_dir.cxx b/simgear/misc/sg_dir.cxx index c575c053..0aea771b 100644 --- a/simgear/misc/sg_dir.cxx +++ b/simgear/misc/sg_dir.cxx @@ -44,6 +44,7 @@ #include #include #include +#include // for std::sort using std::string; @@ -124,6 +125,11 @@ Dir Dir::tempDir(const std::string& templ) #endif } +static bool pathSortPredicate(const SGPath& p1, const SGPath& p2) +{ + return p1.file() < p2.file(); +} + PathList Dir::children(int types, const std::string& nameFilter) const { PathList result; @@ -241,6 +247,11 @@ PathList Dir::children(int types, const std::string& nameFilter) const closedir(dp); #endif + + // File system order is random. Make things deterministic, + // so it's the same for every user. + std::sort(result.begin(), result.end(), pathSortPredicate); + return result; } -- 2.39.5