diff options
| author | Teddy Wing | 2021-05-30 18:38:09 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-05-30 18:38:09 +0200 | 
| commit | 82c0b2cab1ed03188b0178d04b5a0090ec5cd60b (patch) | |
| tree | 031035fcfd899c30c5e4bfbb29bd202fa45b7a4b | |
| parent | df4d04b481f39018fa4146f198207f42a1fdceef (diff) | |
| download | reflectub-82c0b2cab1ed03188b0178d04b5a0090ec5cd60b.tar.bz2 | |
main::mirror(): Make the base cgitrc file optional
Allow user to not be required to specify a base cgitrc file for cloned
repositories.
| -rw-r--r-- | src/main.rs | 25 | 
1 files changed, 16 insertions, 9 deletions
| 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<P: AsRef<Path>>(base_path: P, repo: &github::Repo) -> PathBuf {  fn mirror<P: AsRef<Path>>(      clone_path: P,      repo: &github::Repo, -    base_cgitrc: P, +    base_cgitrc: Option<P>,  ) -> anyhow::Result<()> {      // mirror database      // update description @@ -114,13 +118,16 @@ fn mirror<P: AsRef<Path>>(      )?;      // 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(())  } | 
