From 82c0b2cab1ed03188b0178d04b5a0090ec5cd60b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 May 2021 18:38:09 +0200 Subject: main::mirror(): Make the base cgitrc file optional Allow user to not be required to specify a base cgitrc file for cloned repositories. --- src/main.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 144b578..0977829 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,7 +72,11 @@ async fn main() { }, Err(database::Error::Db(sqlx::Error::RowNotFound)) => { - mirror(&path, &repo, &"./cgitrc".to_owned().into()).unwrap(); + mirror( + &path, + &repo, + Some(&"./cgitrc".to_owned().into()), + ).unwrap(); db.repo_insert(db_repo).await.unwrap(); }, @@ -101,7 +105,7 @@ fn clone_path>(base_path: P, repo: &github::Repo) -> PathBuf { fn mirror>( clone_path: P, repo: &github::Repo, - base_cgitrc: P, + base_cgitrc: Option

, ) -> anyhow::Result<()> { // mirror database // update description @@ -114,13 +118,16 @@ fn mirror>( )?; // Copy the base cgitrc file into the newly-cloned repository. - let cgitrc_path = clone_path.as_ref().join("cgitrc"); - fs::copy(&base_cgitrc, &cgitrc_path) - .with_context(|| format!( - "unable to copy '{}' to '{}'", - "./cgitrc", - &cgitrc_path.display(), - ))?; + if let Some(base_cgitrc) = base_cgitrc { + let cgitrc_path = clone_path.as_ref().join("cgitrc"); + + fs::copy(&base_cgitrc, &cgitrc_path) + .with_context(|| format!( + "unable to copy '{}' to '{}'", + "./cgitrc", + &cgitrc_path.display(), + ))?; + } Ok(()) } -- cgit v1.2.3