diff options
| -rw-r--r-- | Cargo.lock | 30 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/main.rs | 36 | 
3 files changed, 63 insertions, 5 deletions
| @@ -128,6 +128,7 @@ dependencies = [   "libc",   "num-integer",   "num-traits", + "time",   "winapi",  ] @@ -227,6 +228,18 @@ dependencies = [  ]  [[package]] +name = "filetime" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi", +] + +[[package]]  name = "fnv"  version = "1.0.7"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1010,6 +1023,8 @@ name = "reflectub"  version = "0.0.1"  dependencies = [   "anyhow", + "chrono", + "filetime",   "git2",   "reqwest",   "serde", @@ -1412,6 +1427,17 @@ dependencies = [  ]  [[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]]  name = "tinyvec"  version = "1.2.0"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1615,9 +1641,9 @@ dependencies = [  [[package]]  name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1"  source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"  [[package]]  name = "wasm-bindgen" @@ -5,6 +5,8 @@ edition = "2018"  [dependencies]  anyhow = "1.0.40" +chrono = "0.4.19" +filetime = "0.2.14"  git2 = "0.13.20"  reqwest = { version = "0.11.3", features = ["json"] }  serde = { version = "1.0.126", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index 9689d3c..bae2da8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@  use anyhow::{self, Context}; +use chrono::DateTime; +use filetime;  use sqlx;  use tokio; @@ -10,9 +12,9 @@ use std::path::{Path, PathBuf};  #[tokio::main]  async fn main() { -    let repos = github::fetch_repos("teddywing").await.unwrap(); - -    dbg!(&repos); +    // let repos = github::fetch_repos("teddywing").await.unwrap(); +    // +    // dbg!(&repos);      // git::mirror(      //     "https://github.com/teddywing/google-calendar-rsvp.git", @@ -22,6 +24,8 @@ async fn main() {      // git::update(      //     Path::new("/tmp/grsvp"),      // ).unwrap(); + +    run().await.unwrap();  }  async fn run() -> anyhow::Result<()> { @@ -129,6 +133,8 @@ fn mirror<P: AsRef<Path>>(              ))?;      } +    update_mtime(&clone_path, &repo)?; +      Ok(())  } @@ -145,5 +151,29 @@ fn update<P: AsRef<Path>>(          git::update_description(&repo_path, remote_description)?;      } +    update_mtime(&repo_path, &updated_repo)?; + +    Ok(()) +} + +fn update_mtime<P: AsRef<Path>>( +    repo_path: P, +    repo: &github::Repo, +) -> anyhow::Result<()> { +    let default_branch_ref = repo_path +        .as_ref() +        .join("refs/heads") +        .join(&repo.default_branch); + +    let update_time = filetime::FileTime::from_system_time( +        DateTime::parse_from_rfc3339(&repo.updated_at)?.into() +    ); + +    filetime::set_file_times(&default_branch_ref, update_time, update_time) +        .with_context(|| format!( +            "unable to set mtime on '{}'", +            &default_branch_ref.display(), +        ))?; +      Ok(())  } | 
