From df4d04b481f39018fa4146f198207f42a1fdceef Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 May 2021 18:35:47 +0200 Subject: main::mirror(): Copy a base cgitrc file into the mirrored repository This lets us define common cgitrc configuration for all mirrored repos. --- src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 697ca7e..144b578 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ -use anyhow; +use anyhow::{self, Context}; use sqlx; use tokio; use reflectub::{database, git, github}; +use std::fs; use std::path::{Path, PathBuf}; @@ -71,7 +72,7 @@ async fn main() { }, Err(database::Error::Db(sqlx::Error::RowNotFound)) => { - mirror(&path, &repo).unwrap(); + mirror(&path, &repo, &"./cgitrc".to_owned().into()).unwrap(); db.repo_insert(db_repo).await.unwrap(); }, @@ -100,6 +101,7 @@ fn clone_path>(base_path: P, repo: &github::Repo) -> PathBuf { fn mirror>( clone_path: P, repo: &github::Repo, + base_cgitrc: P, ) -> anyhow::Result<()> { // mirror database // update description @@ -111,6 +113,15 @@ fn mirror>( repo.description(), )?; + // 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(), + ))?; + Ok(()) } -- cgit v1.2.3