diff options
author | Teddy Wing | 2021-05-30 15:02:37 +0200 |
---|---|---|
committer | Teddy Wing | 2021-05-30 15:02:37 +0200 |
commit | 80a1cda7f857dbb2e776253225446351228072fb (patch) | |
tree | 2c56b8cd5ad14c13327bd4027df007078c763341 /src/main.rs | |
parent | bb57eb9167740b8b14b87aafae3898a2517d0909 (diff) | |
download | reflectub-80a1cda7f857dbb2e776253225446351228072fb.tar.bz2 |
main: Mirror new repositories
If we haven't encountered a repository yet, mirror it to the filesystem.
Change `From<github::Repo>` to `From<&github::Repo>` so we don't consume
the repo and can use it later in the repo list loop.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index ea7a45b..478ffab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,9 @@ async fn main() { for repo in test_repos { let id = repo.id; - let db_repo = database::Repo::from(repo); + let clone_path = Path::new("/tmp") + .join(format!("{}.git", repo.name)); + let db_repo = database::Repo::from(&repo); match db.repo_get(id).await { Ok(r) => { @@ -69,7 +71,10 @@ async fn main() { }, Err(database::Error::Db(sqlx::Error::RowNotFound)) => { - mirror().unwrap(); + mirror( + &repo.git_url, + &clone_path, + ).unwrap(); db.repo_insert(db_repo).await.unwrap(); }, @@ -80,10 +85,15 @@ async fn main() { } -fn mirror() -> Result<(), Box<dyn std::error::Error>> { +fn mirror<P: AsRef<Path>>( + url: &str, + clone_path: P, +) -> Result<(), Box<dyn std::error::Error>> { // mirror database // update description // copy cgitrc + git::mirror(url, clone_path)?; + Ok(()) } |