From 1afd7b465f9bd22ee5362327a5833f43ef7d70ba Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Tue, 7 Nov 2023 16:22:37 -0500 Subject: [PATCH] add check that index-dir exists --- src/main.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 46931fa..a24c91d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -550,6 +550,23 @@ async fn ensure_dir_exists>(path: P) -> Result<(), Any } } +async fn verify_dir_exists>(path: P) -> Result<(), AnyError> { + match tokio::fs::metadata(path.as_ref()).await { + Ok(meta) if meta.is_dir() => Ok(()), + + Ok(meta) /* if ! meta.is_dir() */ => { + debug_assert!( ! meta.is_dir()); + Err(format!("path exists, but is not a directory: {:?}", path.as_ref()).into()) + } + + Err(e) if e.kind() == std::io::ErrorKind::NotFound => { + Err(format!("path does not exist: {}", path.as_ref().display()).into()) + } + + Err(e) => Err(e.into()), + } +} + async fn ensure_file_parent_dir_exists>(path: P) -> Result<(), AnyError> { if let Some(parent_dir) = path.as_ref().parent() { ensure_dir_exists(parent_dir).await @@ -757,7 +774,10 @@ async fn run(config: Config) -> Result<(), AnyError> { tmp } - (_, Some(path)) => path, + (_, Some(path)) => { + verify_dir_exists(&path).await?; + path + } _ => unreachable!(), };