about summary refs log tree commit diff
path: root/tvix/castore/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-12T13·55+0200
committerclbot <clbot@tvl.fyi>2023-12-12T18·07+0000
commit81ef26ba3f5e03b72bfcf6d02b69583d658bc157 (patch)
tree180caa93a0b3d42b8b215048da33c38d46810dda /tvix/castore/src
parentafd09c32907fd3267de3fb63df281b842ed6b736 (diff)
fix(tvix/castore/import): don't unwrap entry r/7209
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 <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore/src')
-rw-r--r--tvix/castore/src/import.rs10
1 files changed, 8 insertions, 2 deletions
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<P: AsRef<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<P: AsRef<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<Directory> in case the entry points to a directory.
         // make sure to provide it.