Don't write unchanged files
This commit is contained in:
parent
e01de41925
commit
e0cb1c8f23
1 changed files with 10 additions and 5 deletions
|
|
@ -141,7 +141,6 @@ impl Files {
|
||||||
pub fn save(&self) -> Result<()> {
|
pub fn save(&self) -> Result<()> {
|
||||||
for file in &self.files {
|
for file in &self.files {
|
||||||
if file.dirty {
|
if file.dirty {
|
||||||
println!("Saving file {:?}", file.path);
|
|
||||||
Self::save_file(&file.path, &file.file)?;
|
Self::save_file(&file.path, &file.file)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,10 +148,16 @@ impl Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_file(path: &Path, file: &File) -> Result<()> {
|
fn save_file(path: &Path, file: &File) -> Result<()> {
|
||||||
fs::write(path, &format!("{}", file)).map_err(|e| Error::WriteFile {
|
let formatted = format!("{}", file);
|
||||||
|
if file.contents == formatted {
|
||||||
|
println!("Unchanged file {:?}", path);
|
||||||
|
} else {
|
||||||
|
println!("Saving file {:?}", path);
|
||||||
|
fs::write(path, &formatted).map_err(|e| Error::WriteFile {
|
||||||
file: path.to_path_buf(),
|
file: path.to_path_buf(),
|
||||||
error: e,
|
error: e,
|
||||||
})?;
|
})?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue