diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-06-16T16·16+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-06-16T16·16+0000 |
commit | 727beb798a701ff546adc65030f1562b87283947 (patch) | |
tree | 35d7efad8474d2da096dd1026c784df5d585e9b7 | |
parent | 2f04e7102eaad3159073019af96e6e5c4f2c9bcf (diff) |
* Canonicalization: when hashing directories, sort the directory
entries by name.
-rw-r--r-- | src/hash.cc | 20 |
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 */ } |