From f3d2cee56389bb41fd539137358eb9dbc884c49f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 25 Jun 2021 00:41:22 +0200 Subject: 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. --- src/main.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') 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>( &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>( + 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>( &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(), -- cgit v1.2.3