Use same path for saving files as for loading

This commit is contained in:
Joscha 2022-01-06 18:22:26 +01:00
parent a4a6726091
commit 80666c2cf5

View file

@ -267,21 +267,21 @@ 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 {
Self::save_file(&file.path, &file.file)?; Self::save_file(file)?;
} }
} }
Ok(()) Ok(())
} }
fn save_file(path: &Path, file: &File) -> Result<()> { fn save_file(file: &LoadedFile) -> Result<()> {
// TODO Sort commands within file // TODO Sort commands within file
let formatted = format!("{}", file); let formatted = format!("{}", file.file);
if file.contents == formatted { if file.file.contents == formatted {
println!("Unchanged file {:?}", path); println!("Unchanged file {:?}", file.name);
} else { } else {
println!("Saving file {:?}", path); println!("Saving file {:?}", file.name);
fs::write(path, &formatted).map_err(|e| Error::WriteFile { fs::write(&file.name, &formatted).map_err(|e| Error::WriteFile {
file: path.to_path_buf(), file: file.name.to_path_buf(),
error: e, error: e,
})?; })?;
} }