diff options
| author | Teddy Wing | 2021-05-30 18:35:47 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-05-30 18:35:47 +0200 | 
| commit | df4d04b481f39018fa4146f198207f42a1fdceef (patch) | |
| tree | 662cd70a9585c5a4ba220c8410e59f165580ac9a | |
| parent | 850b2aadd402ab80c0d2c371fe7be3066271a1ab (diff) | |
| download | reflectub-df4d04b481f39018fa4146f198207f42a1fdceef.tar.bz2 | |
main::mirror(): Copy a base cgitrc file into the mirrored repository
This lets us define common cgitrc configuration for all mirrored repos.
| -rw-r--r-- | src/main.rs | 15 | 
1 files changed, 13 insertions, 2 deletions
| 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<P: AsRef<Path>>(base_path: P, repo: &github::Repo) -> PathBuf {  fn mirror<P: AsRef<Path>>(      clone_path: P,      repo: &github::Repo, +    base_cgitrc: P,  ) -> anyhow::Result<()> {      // mirror database      // update description @@ -111,6 +113,15 @@ fn mirror<P: AsRef<Path>>(          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(())  } | 
