diff options
author | Florian Klink <flokli@flokli.de> | 2023-12-21T14·52+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-12-21T16·28+0000 |
commit | 88adaea12babf9b32578e86a75b5f2eef79ba4a3 (patch) | |
tree | a0840bfda41232a8bc04de6b8a1342e0cddeaa6f | |
parent | 9065089b0c4b16237cacf7c0878779cffb7f520f (diff) |
refactor(nix-compat/store_path/utils): restructure build_ca_path r/7237
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 <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: edef <edef@edef.eu>
-rw-r--r-- | tvix/nix-compat/src/store_path/utils.rs | 58 |
1 files 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<str>, I: IntoIterator<Item = S>>( references: I, self_reference: bool, ) -> Result<StorePathRef<'a>, 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<str>, I: IntoIterator<Item = S>>( 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<str>, I: IntoIterator<Item = S>>( 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 |