about summary refs log tree commit diff
path: root/src/hash.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.cc')
-rw-r--r--src/hash.cc20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/hash.cc b/src/hash.cc
index 9558d36705f3..37f6104fb0d6 100644
--- a/src/hash.cc
+++ b/src/hash.cc
@@ -154,24 +154,30 @@ static void dumpEntries(const string & path, DumpSink & sink)
 {
     DIR * dir = opendir(path.c_str());
     if (!dir) throw SysError("opening directory " + path);
-    
-    struct dirent * dirent;
 
-    /* !!! sort entries */
+    Strings names;
 
+    struct dirent * dirent;
     while (errno = 0, dirent = readdir(dir)) {
         string name = dirent->d_name;
         if (name == "." || name == "..") continue;
+        names.push_back(name);
+    }
+    if (errno) throw SysError("reading directory " + path);
+
+    sort(names.begin(), names.end());
+
+    for (Strings::iterator it = names.begin();
+         it != names.end(); it++)
+    {
         writeString("entry", sink);
         writeString("(", sink);
         writeString("name", sink);
-        writeString(name, sink);
+        writeString(*it, sink);
         writeString("file", sink);
-        dumpPath(path + "/" + name, sink);
+        dumpPath(path + "/" + *it, sink);
         writeString(")", sink);
     }
-
-    if (errno) throw SysError("reading directory " + path);
     
     closedir(dir); /* !!! close on exception */
 }