From 81ef26ba3f5e03b72bfcf6d02b69583d658bc157 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 12 Dec 2023 15:55:55 +0200 Subject: fix(tvix/castore/import): don't unwrap entry If the path specified doesn't exist, construct a proper error instead of panicking. Part of b/344. Change-Id: Id5c6a91248b0a387f3e8f138f8e686e402009e8f Reviewed-on: https://cl.tvl.fyi/c/depot/+/10330 Autosubmit: flokli Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/castore/src/import.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tvix/castore') diff --git a/tvix/castore/src/import.rs b/tvix/castore/src/import.rs index 6b24c7a52b22..e933205ab6bd 100644 --- a/tvix/castore/src/import.rs +++ b/tvix/castore/src/import.rs @@ -155,7 +155,7 @@ pub async fn ingest_path + Debug>( let mut directory_putter = directory_service.put_multiple_start(); - for entry in WalkDir::new(p) + for entry in WalkDir::new(p.as_ref()) .follow_links(false) .follow_root_links(false) // We need to process a directory's children before processing @@ -164,7 +164,13 @@ pub async fn ingest_path + Debug>( .contents_first(true) .sort_by_file_name() { - let entry = entry.unwrap(); + // Entry could be a NotFound, if the root path specified does not exist. + let entry = entry.map_err(|e| { + Error::UnableToOpen( + PathBuf::from(p.as_ref()), + e.into_io_error().expect("walkdir err must be some"), + ) + })?; // process_entry wants an Option in case the entry points to a directory. // make sure to provide it. -- cgit 1.4.1