diff options
author | Teddy Wing | 2021-06-25 00:41:22 +0200 |
---|---|---|
committer | Teddy Wing | 2021-06-25 00:55:47 +0200 |
commit | f3d2cee56389bb41fd539137358eb9dbc884c49f (patch) | |
tree | 20391f2f197ddd959bd208356784a878f66aba2c /src | |
parent | eb35a636b5324d42d4077a0af0dd5944a94b9158 (diff) | |
download | reflectub-f3d2cee56389bb41fd539137358eb9dbc884c49f.tar.bz2 |
set_agefile_time: Move repo cgitrc file append to a function
I need to add another line to the repo-local cgitrc file to set the
default branch. Move this code to a function so we can reuse it.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 878bd73..a28eac2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -387,9 +387,23 @@ fn set_agefile_time<P: AsRef<Path>>( &agefile_path.display(), ))?; + repo_cgitrc_append( + &repo_path, + "agefile=info/web/last-modified", + )?; + + Ok(()) +} + +/// Append `config` to the repo-local "cgitrc" file. +fn repo_cgitrc_append<P: AsRef<Path>>( + repo_path: P, + config: &str, +) -> anyhow::Result<()> { let cgitrc_path = repo_path .as_ref() .join("cgitrc"); + let mut cgitrc_file = fs::OpenOptions::new() .append(true) .create(true) @@ -399,11 +413,7 @@ fn set_agefile_time<P: AsRef<Path>>( &cgitrc_path.display(), ))?; - writeln!( - cgitrc_file, - "{}", - "agefile=info/web/last-modified", - ) + writeln!(cgitrc_file, "{}", config) .with_context(|| format!( "unable to write to '{}'", &cgitrc_path.display(), |