feat: append to *.src file

This commit is contained in:
2022-08-06 16:10:30 +08:00
parent bfed66a7ae
commit 049163d511

View File

@@ -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);
}
}