refactor(nix-compat/store_path): centralize self_reference check
self_reference being set to true is only allowed for `CAHash::Nar(NixHash::Sha256(_))`, so we can handle this in a check at the front. Change-Id: Ic363ade4789a7767cbe26a6959b143bb53e50e5a Reviewed-on: https://cl.tvl.fyi/c/depot/+/10391 Reviewed-by: edef <edef@edef.eu> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
		
							parent
							
								
									88adaea12b
								
							
						
					
					
						commit
						329a7d30a7
					
				
					 1 changed files with 12 additions and 16 deletions
				
			
		|  | @ -61,29 +61,28 @@ pub fn build_ca_path<'a, S: AsRef<str>, I: IntoIterator<Item = S>>( | ||||||
|     references: I, |     references: I, | ||||||
|     self_reference: bool, |     self_reference: bool, | ||||||
| ) -> Result<StorePathRef<'a>, BuildStorePathError> { | ) -> Result<StorePathRef<'a>, BuildStorePathError> { | ||||||
|     let (ty, hash) = match &ca_hash { |     // self references are only allowed for CAHash::Nar(NixHash::Sha256(_)).
 | ||||||
|         CAHash::Text(ref digest) => { |  | ||||||
|     if self_reference { |     if self_reference { | ||||||
|  |         let CAHash::Nar(NixHash::Sha256(_)) = ca_hash else { | ||||||
|             return Err(BuildStorePathError::InvalidReference()); |             return Err(BuildStorePathError::InvalidReference()); | ||||||
|  |         }; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|             ( |     let (ty, hash) = match &ca_hash { | ||||||
|  |         CAHash::Text(ref digest) => ( | ||||||
|             make_references_string("text", references, false), |             make_references_string("text", references, false), | ||||||
|             NixHash::Sha256(*digest), |             NixHash::Sha256(*digest), | ||||||
|             ) |         ), | ||||||
|         } |  | ||||||
|         CAHash::Nar(NixHash::Sha256(ref digest)) => ( |         CAHash::Nar(NixHash::Sha256(ref digest)) => ( | ||||||
|             make_references_string("source", references, self_reference), |             make_references_string("source", references, self_reference), | ||||||
|             NixHash::Sha256(*digest), |             NixHash::Sha256(*digest), | ||||||
|         ), |         ), | ||||||
|  | 
 | ||||||
|         // for all other CAHash::Nar, another custom scheme is used.
 |         // for all other CAHash::Nar, another custom scheme is used.
 | ||||||
|         CAHash::Nar(ref hash) => { |         CAHash::Nar(ref hash) => { | ||||||
|             if references.into_iter().next().is_some() { |             if references.into_iter().next().is_some() { | ||||||
|                 return Err(BuildStorePathError::InvalidReference()); |                 return Err(BuildStorePathError::InvalidReference()); | ||||||
|             } |             } | ||||||
|             if self_reference { |  | ||||||
|                 return Err(BuildStorePathError::InvalidReference()); |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             ( |             ( | ||||||
|                 "output:out".to_string(), |                 "output:out".to_string(), | ||||||
|  | @ -99,9 +98,6 @@ pub fn build_ca_path<'a, S: AsRef<str>, I: IntoIterator<Item = S>>( | ||||||
|             if references.into_iter().next().is_some() { |             if references.into_iter().next().is_some() { | ||||||
|                 return Err(BuildStorePathError::InvalidReference()); |                 return Err(BuildStorePathError::InvalidReference()); | ||||||
|             } |             } | ||||||
|             if self_reference { |  | ||||||
|                 return Err(BuildStorePathError::InvalidReference()); |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             ( |             ( | ||||||
|                 "output:out".to_string(), |                 "output:out".to_string(), | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue