diff options
author | edef <edef@edef.eu> | 2023-10-27T11·45+0000 |
---|---|---|
committer | edef <edef@edef.eu> | 2023-10-27T13·56+0000 |
commit | 6238a05868c8597183023e34cb7f47e9d64270eb (patch) | |
tree | c7a396c700c109913e6786dc510f245c5979eed3 /tvix/nix-compat/src | |
parent | 7f7c1ae7be97a54e8a52bda29e6d2c22f2efb822 (diff) |
refactor(nix-compat/store_path): don't materialise fingerprint r/6889
Change-Id: I6a88531ded05c0dfb9232a0343a465fa02fb6989 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9856 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src')
-rw-r--r-- | tvix/nix-compat/src/store_path/utils.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/tvix/nix-compat/src/store_path/utils.rs b/tvix/nix-compat/src/store_path/utils.rs index 375882795c31..31964bc6b1ff 100644 --- a/tvix/nix-compat/src/store_path/utils.rs +++ b/tvix/nix-compat/src/store_path/utils.rs @@ -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 |