Skip to content

Commit

Permalink
fix deshaw#9: Do not overwrite file if contents are identical.
Browse files Browse the repository at this point in the history
  • Loading branch information
randolf-scholz committed Aug 23, 2023
1 parent 46cf0ef commit f1fc65d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,17 @@ fn process_file(
})?;
let cleaned_contents = String::from_utf8(ser.into_inner()).map_err(|e| format!("{:?}", e))?;

if let Some(file) = output_file {
fs::write(&file, cleaned_contents)
.map_err(|e| format!("Could not write to {:?} due to {:?}", file, e))?;
if cleaned_contents != *contents {
if let Some(file) = output_file {
fs::write(&file, cleaned_contents)
.map_err(|e| format!("Could not write to {:?} due to {:?}", file, e))?;
} else {
println!("{}", cleaned_contents);
}
} else {
println!("{}", cleaned_contents);
println!("Content unchanged. File not modified.");
}

Ok(())
}

Expand Down

0 comments on commit f1fc65d

Please sign in to comment.