From fa335aaa68b0875e861aff09536ef10e0b847f70 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 31 Dec 2023 18:20:54 +0200 Subject: fix(tvix/store/bin): don't unwrap in case of invalid paths Instead, return an error, and move the entire check before starting to ingest the data underneath. Change-Id: Idcfba115cb7d599f5fc72a156aaad9d4d4714fcf Reviewed-on: https://cl.tvl.fyi/c/depot/+/10507 Reviewed-by: raitobezarius Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/store/src/bin/tvix-store.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs index f241a80bf575..919294f697b3 100644 --- a/tvix/store/src/bin/tvix-store.rs +++ b/tvix/store/src/bin/tvix-store.rs @@ -261,6 +261,17 @@ async fn main() -> Result<(), Box> { let path_info_service = path_info_service.clone(); async move { + // calculate the name + let name = path + .file_name() + .and_then(|file_name| file_name.to_str()) + .ok_or_else(|| { + std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "path must not be .. and the basename valid unicode", + ) + })?; + // Ingest the path into blob and directory service. let root_node = import::ingest_path( blob_service.clone(), @@ -271,15 +282,8 @@ async fn main() -> Result<(), Box> { .expect("failed to ingest path"); // Ask the PathInfoService for the NAR size and sha256 - let root_node_copy = root_node.clone(); let (nar_size, nar_sha256) = - path_info_service.calculate_nar(&root_node_copy).await?; - - let name = path - .file_name() - .expect("path must not be ..") - .to_str() - .expect("path must be valid unicode"); + path_info_service.calculate_nar(&root_node).await?; let output_path = store_path::build_nar_based_store_path(&nar_sha256, name); -- cgit 1.4.1