about summary refs log tree commit diff
path: root/tvix/derivation/src/output.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-01-31T13·45+0100
committerclbot <clbot@tvl.fyi>2023-01-31T15·16+0000
commit2d24c5f260945216ca01371d4120f5d53f08b2cd (patch)
tree5053bbffefd5a41241ab6ea27fafc290e44e665f /tvix/derivation/src/output.rs
parent9e809e21ccb1768567fc2516c5526ad0cdd56df0 (diff)
refactor(tvix/nix-compat): absorb //tvix/derivation r/5791
Put this in its src/derivation.

Change-Id: Ic047ab1c2da555a833ee454e10ef60c77537b617
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7967
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/derivation/src/output.rs')
-rw-r--r--tvix/derivation/src/output.rs55
1 files changed, 0 insertions, 55 deletions
diff --git a/tvix/derivation/src/output.rs b/tvix/derivation/src/output.rs
deleted file mode 100644
index 828f42be74ca..000000000000
--- a/tvix/derivation/src/output.rs
+++ /dev/null
@@ -1,55 +0,0 @@
-use nix_compat::{nixbase32, store_path::StorePath};
-use serde::{Deserialize, Serialize};
-
-use crate::OutputError;
-
-#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
-pub struct Output {
-    pub path: String,
-
-    #[serde(flatten)]
-    pub hash: Option<Hash>,
-}
-
-#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
-pub struct Hash {
-    #[serde(rename = "hash")]
-    pub digest: String,
-    #[serde(rename = "hashAlgo")]
-    pub algo: String,
-}
-
-impl Output {
-    pub fn is_fixed(&self) -> bool {
-        self.hash.is_some()
-    }
-
-    pub fn validate(&self, validate_output_paths: bool) -> Result<(), OutputError> {
-        if let Some(hash) = &self.hash {
-            // try to decode digest
-            let result = nixbase32::decode(&hash.digest.as_bytes());
-            match result {
-                Err(e) => return Err(OutputError::InvalidHashEncoding(hash.digest.clone(), e)),
-                Ok(digest) => {
-                    if hash.algo != "sha1" && hash.algo != "sha256" {
-                        return Err(OutputError::InvalidHashAlgo(hash.algo.to_string()));
-                    }
-                    if (hash.algo == "sha1" && digest.len() != 20)
-                        || (hash.algo == "sha256" && digest.len() != 32)
-                    {
-                        return Err(OutputError::InvalidDigestSizeForAlgo(
-                            digest.len(),
-                            hash.algo.to_string(),
-                        ));
-                    }
-                }
-            };
-        }
-        if validate_output_paths {
-            if let Err(e) = StorePath::from_absolute_path(&self.path) {
-                return Err(OutputError::InvalidOutputPath(self.path.to_string(), e));
-            }
-        }
-        Ok(())
-    }
-}