diff options
author | Florian Klink <flokli@flokli.de> | 2023-12-31T16·20+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-12-31T22·23+0000 |
commit | fa335aaa68b0875e861aff09536ef10e0b847f70 (patch) | |
tree | aca12c5cff6d79262007807482847689c4ac0642 /tvix | |
parent | 694ed7ea1a8fe61b90c103639ef1964ce6173761 (diff) |
fix(tvix/store/bin): don't unwrap in case of invalid paths r/7297
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 <tvl@lahfa.xyz> Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/store/src/bin/tvix-store.rs | 20 |
1 files 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<dyn std::error::Error>> { 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<dyn std::error::Error>> { .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); |