From bf7a7db86807bfaf262f9f3d23a99df8c120b515 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 4 May 2024 20:13:38 +0200 Subject: [PATCH] feat: I dunno why Signed-off-by: kjuulh --- cuddle/src/cli/subcommands/init.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cuddle/src/cli/subcommands/init.rs b/cuddle/src/cli/subcommands/init.rs index aacc9ec..74610d1 100644 --- a/cuddle/src/cli/subcommands/init.rs +++ b/cuddle/src/cli/subcommands/init.rs @@ -3,6 +3,7 @@ use std::fs::{create_dir_all, read, read_dir}; use std::io::Write; use std::path::PathBuf; +use anyhow::Context; use clap::{ArgMatches, Command}; use walkdir::WalkDir; @@ -178,8 +179,16 @@ pub fn execute_init(exe_submatch: &ArgMatches, _cli: CuddleCli) -> anyhow::Resul } tracing::info!("writing to: {}", new_path.display()); - let new_content = - replace_with_variables(&std::fs::read_to_string(entry_path)?, &template)?; + + let old_content = match std::fs::read_to_string(entry_path) { + Ok(e) => e, + Err(e) => { + tracing::debug!("found invalid file possibly with invalid utf8: {}", e); + std::fs::copy(entry_path, new_path).context("failed to write file")?; + continue; + } + }; + let new_content = replace_with_variables(&old_content, &template)?; std::fs::write(new_path, new_content.as_bytes())?; }