Set up the flake repo directory.

This commit is contained in:
Tom Alexander
2026-02-14 16:00:37 -05:00
parent 9344e5708f
commit 7ec243e3e4
11 changed files with 449 additions and 19 deletions

36
src/fs_util.rs Normal file
View File

@@ -0,0 +1,36 @@
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
}