Browse Source

add check that index-dir exists

feat/mass-publish-tool
Jonathan Strong 1 year ago
parent
commit
1afd7b465f
  1. 22
      src/main.rs

22
src/main.rs

@ -550,6 +550,23 @@ async fn ensure_dir_exists<P: AsRef<std::path::Path>>(path: P) -> Result<(), Any
}
}
async fn verify_dir_exists<P: AsRef<std::path::Path>>(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<P: AsRef<std::path::Path>>(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!(),
};

Loading…
Cancel
Save