usestd::fs;usestd::io::Write;usestd::path::Path;/// Atomically writes `content` to `target_path` using a temporary file and sync/rename.
////// Flushes and syncs to disk before renaming so concurrent readers never
/// observe a partially written file or stale mtime.
pubfnwrite_file_atomically_with_temp(target_path:&Path,
temp_path:&Path,
content:&str,
)->anyhow::Result<()>{{letmut f =fs::OpenOptions::new().create(true).write(true).truncate(true).open(temp_path)?;
f.write_all(content.as_bytes())?;
f.sync_all()?;}if target_path.exists(){let_=fs::remove_file(target_path);}fs::rename(temp_path, target_path)?;Ok(())}