mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
* Canonicalization: when hashing directories, sort the directory
entries by name.
This commit is contained in:
parent
2f04e7102e
commit
727beb798a
1 changed files with 14 additions and 8 deletions
22
src/hash.cc
22
src/hash.cc
|
@ -154,24 +154,30 @@ static void dumpEntries(const string & path, DumpSink & sink)
|
||||||
{
|
{
|
||||||
DIR * dir = opendir(path.c_str());
|
DIR * dir = opendir(path.c_str());
|
||||||
if (!dir) throw SysError("opening directory " + path);
|
if (!dir) throw SysError("opening directory " + path);
|
||||||
|
|
||||||
|
Strings names;
|
||||||
|
|
||||||
struct dirent * dirent;
|
struct dirent * dirent;
|
||||||
|
|
||||||
/* !!! sort entries */
|
|
||||||
|
|
||||||
while (errno = 0, dirent = readdir(dir)) {
|
while (errno = 0, dirent = readdir(dir)) {
|
||||||
string name = dirent->d_name;
|
string name = dirent->d_name;
|
||||||
if (name == "." || name == "..") continue;
|
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("entry", sink);
|
||||||
writeString("(", sink);
|
writeString("(", sink);
|
||||||
writeString("name", sink);
|
writeString("name", sink);
|
||||||
writeString(name, sink);
|
writeString(*it, sink);
|
||||||
writeString("file", sink);
|
writeString("file", sink);
|
||||||
dumpPath(path + "/" + name, sink);
|
dumpPath(path + "/" + *it, sink);
|
||||||
writeString(")", sink);
|
writeString(")", sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno) throw SysError("reading directory " + path);
|
|
||||||
|
|
||||||
closedir(dir); /* !!! close on exception */
|
closedir(dir); /* !!! close on exception */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue