Attempt order invariance

This commit is contained in:
Jonathan Kelley 2024-03-06 00:05:42 -08:00
parent 45b824346c
commit 73e7c3e560
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
2 changed files with 10 additions and 9 deletions

View file

@ -1,6 +1,6 @@
use std::{
fs::read_to_string,
hash::{DefaultHasher, Hash, Hasher},
hash::{DefaultHasher, Hasher},
process::Command,
};
@ -16,8 +16,6 @@ fn main() {
if contents.trim() == hash.to_string() {
return;
}
panic!("Hashes don't match {} != {}", contents, hash.to_string());
}
// Otherwise, generate the bindings and write the new hash to disk
@ -30,8 +28,8 @@ fn main() {
}
/// Hashes the contents of a directory
fn hash_dir(dir: &str) -> u64 {
let mut hasher = DefaultHasher::new();
fn hash_dir(dir: &str) -> u128 {
let mut out = 0_128;
for entry in std::fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
@ -45,11 +43,14 @@ fn hash_dir(dir: &str) -> u64 {
continue;
}
let contents = std::fs::read(&path).unwrap();
contents.hash(&mut hasher);
// Hash the contents of the file and then add it to the overall hash
// This makes us order invariant
let mut hasher = DefaultHasher::new();
hasher.write(&std::fs::read(&path).unwrap());
out += hasher.finish() as u128;
}
hasher.finish()
out
}
// okay...... so tsc might fail if the user doesn't have it installed

View file

@ -1 +1 @@
6653358969285642234
63611502429846612446