From 88adaea12babf9b32578e86a75b5f2eef79ba4a3 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 21 Dec 2023 16:52:56 +0200 Subject: refactor(nix-compat/store_path/utils): restructure build_ca_path All match cases essentially construct `ty` and `hash`, which is then passed to the `build_store_path_from_fingerprint_parts` function. Change-Id: I01dfd219f9b0ac1afe8af7c6e361ea048117a0e6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10390 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: edef --- tvix/nix-compat/src/store_path/utils.rs | 58 +++++++++++++++------------------ 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/tvix/nix-compat/src/store_path/utils.rs b/tvix/nix-compat/src/store_path/utils.rs index 50a1d98240b3..2e10c33dcdaa 100644 --- a/tvix/nix-compat/src/store_path/utils.rs +++ b/tvix/nix-compat/src/store_path/utils.rs @@ -61,21 +61,20 @@ pub fn build_ca_path<'a, S: AsRef, I: IntoIterator>( references: I, self_reference: bool, ) -> Result, BuildStorePathError> { - match &ca_hash { + let (ty, hash) = match &ca_hash { CAHash::Text(ref digest) => { if self_reference { return Err(BuildStorePathError::InvalidReference()); } - build_store_path_from_fingerprint_parts( - &make_references_string("text", references, false), - &NixHash::Sha256(*digest), - name, + + ( + make_references_string("text", references, false), + NixHash::Sha256(*digest), ) } - CAHash::Nar(ref hash @ NixHash::Sha256(_)) => build_store_path_from_fingerprint_parts( - &make_references_string("source", references, self_reference), - hash, - name, + CAHash::Nar(NixHash::Sha256(ref digest)) => ( + make_references_string("source", references, self_reference), + NixHash::Sha256(*digest), ), // for all other CAHash::Nar, another custom scheme is used. CAHash::Nar(ref hash) => { @@ -85,19 +84,14 @@ pub fn build_ca_path<'a, S: AsRef, I: IntoIterator>( if self_reference { return Err(BuildStorePathError::InvalidReference()); } - build_store_path_from_fingerprint_parts( - "output:out", - &{ - NixHash::Sha256( - Sha256::new_with_prefix(format!( - "fixed:out:r:{}:", - hash.to_nix_hex_string() - )) + + ( + "output:out".to_string(), + NixHash::Sha256( + Sha256::new_with_prefix(format!("fixed:out:r:{}:", hash.to_nix_hex_string())) .finalize() .into(), - ) - }, - name, + ), ) } // CaHash::Flat is using something very similar, except the `r:` prefix. @@ -108,20 +102,20 @@ pub fn build_ca_path<'a, S: AsRef, I: IntoIterator>( if self_reference { return Err(BuildStorePathError::InvalidReference()); } - build_store_path_from_fingerprint_parts( - "output:out", - &{ - NixHash::Sha256( - Sha256::new_with_prefix(format!("fixed:out:{}:", hash.to_nix_hex_string())) - .finalize() - .into(), - ) - }, - name, + + ( + "output:out".to_string(), + NixHash::Sha256( + Sha256::new_with_prefix(format!("fixed:out:{}:", hash.to_nix_hex_string())) + .finalize() + .into(), + ), ) } - } - .map_err(BuildStorePathError::InvalidStorePath) + }; + + build_store_path_from_fingerprint_parts(&ty, &hash, name) + .map_err(BuildStorePathError::InvalidStorePath) } /// For given NAR sha256 digest and name, return the new [StorePathRef] this -- cgit 1.4.1