Do not overwrite files when there are no diffs in Overwrite mode

This commit is contained in:
topecongiro 2017-06-06 15:33:46 +09:00
parent 6a9d7dab0d
commit a64037d0f0

View File

@ -128,9 +128,12 @@ pub fn write_file<T>(text: &StringBuffer,
}
}
WriteMode::Overwrite => {
// Write text directly over original file.
let file = File::create(filename)?;
write_system_newlines(file, text, config)?;
// Write text directly over original file if there is a diff.
let (source, formatted) = source_and_formatted_text(text, filename, config)?;
if source != formatted {
let file = File::create(filename)?;
write_system_newlines(file, text, config)?;
}
}
WriteMode::Plain => {
write_system_newlines(out, text, config)?;