aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2021-06-03 23:35:53 +0200
committerTeddy Wing2021-06-03 23:35:53 +0200
commit3964a27da7cf61b540992387e8553382dffecb46 (patch)
treee8a237c9287039ed3730a8c43974dad20fed0e53 /src
parent654a5b5b58bead8a707d325e79d86bbe93ea2345 (diff)
downloadreflectub-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.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs32
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(),