hash is calculated as the hash of "dir " plus the concatenation, for each child, of its name, a space and its hash. Children are sorted alphabetically before calculating the hash, so the result is unique.
()
| 82 | // each child, of its name, a space and its hash. Children are sorted |
| 83 | // alphabetically before calculating the hash, so the result is unique. |
| 84 | func (d *dir) calculateHash() { |
| 85 | h := fnv.New64a() |
| 86 | h.Write([]byte("dir ")) |
| 87 | for _, c := range d.children { |
| 88 | h.Write([]byte(c.Name())) |
| 89 | h.Write([]byte(" ")) |
| 90 | h.Write(c.Hash()) |
| 91 | } |
| 92 | d.hash = h.Sum([]byte{}) |
| 93 | } |
| 94 | |
| 95 | func (d *dir) Name() string { |
| 96 | return d.name |