diff options
Diffstat (limited to 'tvix/derivation/src/derivation.rs')
-rw-r--r-- | tvix/derivation/src/derivation.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/tvix/derivation/src/derivation.rs b/tvix/derivation/src/derivation.rs index 1e2605f5b931..daccfad6c42e 100644 --- a/tvix/derivation/src/derivation.rs +++ b/tvix/derivation/src/derivation.rs @@ -1,12 +1,12 @@ -use crate::nix_hash; use crate::output::{Hash, Output}; use crate::write; +use crate::{nix_hash, ValidateDerivationError}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::collections::BTreeSet; use std::{collections::BTreeMap, fmt, fmt::Write}; use tvix_store::nixbase32::NIXBASE32; -use tvix_store::store_path::{ParseStorePathError, StorePath, STORE_DIR}; +use tvix_store::store_path::{StorePath, STORE_DIR}; #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct Derivation { @@ -35,7 +35,7 @@ fn build_store_path( is_derivation: bool, path_hash: &[u8], name: &str, -) -> Result<StorePath, ParseStorePathError> { +) -> Result<StorePath, ValidateDerivationError> { let compressed = nix_hash::compress_hash(path_hash, 20); if is_derivation { StorePath::from_string( @@ -50,6 +50,9 @@ fn build_store_path( } else { StorePath::from_string(format!("{}-{}", NIXBASE32.encode(&compressed), name,).as_str()) } + .map_err(|_e| ValidateDerivationError::InvalidOutputName(name.to_string())) + // Constructing the StorePath can only fail if the passed output name was + // invalid, so map errors to a [ValidateDerivationError::InvalidOutputName]. } impl Derivation { @@ -107,7 +110,10 @@ impl Derivation { /// - Take the digest, run hash.CompressHash(digest, 20) on it. /// - Encode it with nixbase32 /// - Use it (and the name) to construct a [StorePath]. - pub fn calculate_derivation_path(&self, name: &str) -> Result<StorePath, ParseStorePathError> { + pub fn calculate_derivation_path( + &self, + name: &str, + ) -> Result<StorePath, ValidateDerivationError> { let mut hasher = Sha256::new(); // collect the list of paths from input_sources and input_derivations @@ -224,7 +230,7 @@ impl Derivation { &mut self, name: &str, drv_replacement_str: &str, - ) -> Result<(), ParseStorePathError> { + ) -> Result<(), ValidateDerivationError> { let mut hasher = Sha256::new(); // Check if the Derivation is fixed output, because they cause |