refactor: extract into separate file

This commit is contained in:
Kasper Juul Hermansen 2025-02-13 22:58:01 +01:00
parent 040f1a8a56
commit 1428181414
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM
2 changed files with 36 additions and 37 deletions

View File

@ -4,43 +4,7 @@ use anyhow::Context;
use crate::model::Project;
pub mod local {
use std::path::Path;
use anyhow::Context;
pub async fn reconcile(source: &Path, dest: &Path) -> anyhow::Result<()> {
for entry in walkdir::WalkDir::new(source) {
let entry = entry?;
let rel = entry.path().strip_prefix(source)?;
let metadata = entry.metadata()?;
if metadata.is_file() {
tracing::trace!("copying file: {}", rel.display());
let dest_path = dest.join(rel);
tokio::fs::copy(entry.path(), &dest_path)
.await
.context(anyhow::anyhow!(
"failed to file directory at: {}",
dest_path.display()
))?;
} else if metadata.is_dir() {
let dest_path = dest.join(rel);
tracing::trace!("creating directory: {}", dest_path.display());
tokio::fs::create_dir_all(&dest_path)
.await
.context(anyhow::anyhow!(
"failed to create directory at: {}",
dest_path.display()
))?;
}
}
Ok(())
}
}
pub mod local;
#[derive(Default)]
pub struct PlanReconciler {}

View File

@ -0,0 +1,35 @@
use std::path::Path;
use anyhow::Context;
pub async fn reconcile(source: &Path, dest: &Path) -> anyhow::Result<()> {
for entry in walkdir::WalkDir::new(source) {
let entry = entry?;
let rel = entry.path().strip_prefix(source)?;
let metadata = entry.metadata()?;
if metadata.is_file() {
tracing::trace!("copying file: {}", rel.display());
let dest_path = dest.join(rel);
tokio::fs::copy(entry.path(), &dest_path)
.await
.context(anyhow::anyhow!(
"failed to file directory at: {}",
dest_path.display()
))?;
} else if metadata.is_dir() {
let dest_path = dest.join(rel);
tracing::trace!("creating directory: {}", dest_path.display());
tokio::fs::create_dir_all(&dest_path)
.await
.context(anyhow::anyhow!(
"failed to create directory at: {}",
dest_path.display()
))?;
}
}
Ok(())
}