refactor(nix-compat/store_path): don't materialise fingerprint

Change-Id: I6a88531ded05c0dfb9232a0343a465fa02fb6989
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9856
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
edef 2023-10-27 11:45:48 +00:00
parent 7f7c1ae7be
commit 6238a05868

View file

@ -2,6 +2,7 @@ use crate::nixbase32;
use crate::nixhash::{CAHash, NixHash};
use crate::store_path::{Error, StorePath, STORE_DIR};
use sha2::{Digest, Sha256};
use std::io::Write;
use thiserror;
/// Errors that can occur when creating a content-addressed store path.
@ -165,16 +166,16 @@ fn build_store_path_from_fingerprint_parts<B: AsRef<[u8]>>(
hash: &NixHash,
name: B,
) -> Result<StorePath, Error> {
let name = name.as_ref();
let name = super::validate_name(name.as_ref())?;
let fingerprint =
String::from(ty) + ":" + &hash.to_nix_hash_string() + ":" + STORE_DIR + ":" + &name;
let digest = Sha256::new_with_prefix(fingerprint).finalize();
let compressed = compress_hash::<20>(&digest);
Ok(StorePath {
digest: compressed,
name,
})
let digest = compress_hash(&{
let mut h = Sha256::new();
write!(h, "{ty}:{}:{STORE_DIR}:{name}", hash.to_nix_hash_string()).unwrap();
h.finalize()
});
Ok(StorePath { digest, name })
}
/// This contains the Nix logic to create "text hash strings", which are used