diff options
author | Teddy Wing | 2021-06-03 23:35:53 +0200 |
---|---|---|
committer | Teddy Wing | 2021-06-03 23:35:53 +0200 |
commit | 3964a27da7cf61b540992387e8553382dffecb46 (patch) | |
tree | e8a237c9287039ed3730a8c43974dad20fed0e53 | |
parent | 654a5b5b58bead8a707d325e79d86bbe93ea2345 (diff) | |
download | reflectub-3964a27da7cf61b540992387e8553382dffecb46.tar.bz2 |
main::update_mtime(): Use the packed-refs file if no default branch ref
A repository cloned with:
$ git clone --mirror REPO
doesn't have any ref files in `repo.git/refs/heads/*`. Instead, the refs
are stored in `repo.git/packed-refs`. Update the pack file if the
default branch ref file doesn't exist. CGit will look at the time on the
'packed-refs' file when that's the case.
-rw-r--r-- | src/main.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 465325e..e20e860 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use tokio; use reflectub::{database, git, github}; use std::fs; +use std::io; use std::path::{Path, PathBuf}; @@ -174,7 +175,36 @@ fn update_mtime<P: AsRef<Path>>( DateTime::parse_from_rfc3339(&repo.updated_at)?.into() ); - filetime::set_file_times(&default_branch_ref, update_time, update_time) + // Try updating times on the default ref. + match filetime::set_file_times( + &default_branch_ref, + update_time, + update_time, + ) { + Ok(_) => Ok(()), + Err(e) => match e.kind() { + // If the default ref file doesn't exist, update times on the + // 'packed-refs' file. + io::ErrorKind::NotFound => { + let packed_refs_path = repo_path + .as_ref() + .join("packed-refs"); + + Ok( + filetime::set_file_times( + &packed_refs_path, + update_time, + update_time, + ) + .with_context(|| format!( + "unable to set mtime on '{}'", + &packed_refs_path.display(), + ))? + ) + }, + _ => Err(e), + }, + } .with_context(|| format!( "unable to set mtime on '{}'", &default_branch_ref.display(), |