37 lines
1.0 KiB
Rust
37 lines
1.0 KiB
Rust
|
|
macro_rules! assert_directory {
|
||
|
|
($dir:expr, $($params:tt)*) => {{
|
||
|
|
let dir = $dir;
|
||
|
|
let metadata = tokio::fs::metadata(&dir).await;
|
||
|
|
match metadata {
|
||
|
|
Ok(metadata) if !metadata.is_dir() => {
|
||
|
|
tracing::info!($($params)*);
|
||
|
|
tokio::fs::create_dir_all(dir).await?;
|
||
|
|
}
|
||
|
|
Err(_) => {
|
||
|
|
tracing::info!($($params)*);
|
||
|
|
tokio::fs::create_dir_all(dir).await?;
|
||
|
|
}
|
||
|
|
Ok(_) => {}
|
||
|
|
};
|
||
|
|
}};
|
||
|
|
}
|
||
|
|
use std::path::Path;
|
||
|
|
|
||
|
|
pub(crate) use assert_directory;
|
||
|
|
|
||
|
|
use crate::error::CustomError;
|
||
|
|
|
||
|
|
pub(crate) async fn is_directory<D: AsRef<Path>>(dir: D) -> Result<bool, CustomError> {
|
||
|
|
let metadata = tokio::fs::metadata(dir).await;
|
||
|
|
let result = match metadata {
|
||
|
|
Ok(metadata) if metadata.is_dir() => true,
|
||
|
|
_ => false,
|
||
|
|
};
|
||
|
|
Ok(result)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub(crate) async fn is_git_repo<D: AsRef<Path>>(dir: D) -> Result<bool, CustomError> {
|
||
|
|
let dot_git = dir.as_ref().join(".git");
|
||
|
|
is_directory(dot_git).await
|
||
|
|
}
|