From 6238a05868c8597183023e34cb7f47e9d64270eb Mon Sep 17 00:00:00 2001 From: edef Date: Fri, 27 Oct 2023 11:45:48 +0000 Subject: refactor(nix-compat/store_path): don't materialise fingerprint Change-Id: I6a88531ded05c0dfb9232a0343a465fa02fb6989 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9856 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/store_path/utils.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tvix/nix-compat/src/store_path/utils.rs') 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>( hash: &NixHash, name: B, ) -> Result { + 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 -- cgit 1.4.1