From 049163d511df666a4e916319c4393ef1e3e4194e Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 6 Aug 2022 16:10:30 +0800 Subject: [PATCH] feat: append to *.src file --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 3716bb6..2087871 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,12 @@ fn write_script_file_to_src(script_file: &String, cache_script_bin_name: String) if let Ok(Some(canonicalized_script_file)) = PathBuf::from(script_file) .canonicalize().map(|f| f.to_str().map(|f| f.to_string())) { let cache_script_bin_name_src = format!("{}.src", cache_script_bin_name); - if let Ok(_) = fs::write(&cache_script_bin_name_src, &format!("{}\n", canonicalized_script_file)) { + let src_content = fs::read_to_string(&cache_script_bin_name_src).ok(); + if src_content.as_ref().map(|c| c.contains(&canonicalized_script_file)).unwrap_or_else(|| false) { + return; + } + let new_src_content = src_content.unwrap_or_else(|| "".to_string()) + &format!("{}\n", canonicalized_script_file); + if let Ok(_) = fs::write(&cache_script_bin_name_src, &new_src_content) { debugging!("Write {} to {}", canonicalized_script_file, cache_script_bin_name_src); } }