prevent ssd extra writes if the post file is up to date

This commit is contained in:
postscriptum 2025-07-01 22:26:18 +03:00
parent 6c5c158272
commit 9c835a9ec0

View file

@ -133,7 +133,20 @@ impl Nex {
.format(&self.filename.trim_matches(std::path::MAIN_SEPARATOR))
.to_string(),
);
fs::write(p, c)?; // @TODO skip overwrite operations
// safe SSD by prevent extra writes
let f = p.to_string_lossy();
if fs::exists(&p)? {
if fs::read_to_string(&p)? != c {
fs::write(&p, c)?;
println!("\t\t\tpost file `{f}` updated with new content.")
} else {
println!("\t\t\tpost file `{f}` is up to date.")
}
} else {
fs::write(&p, c)?;
println!("\t\t\tcreated new post file `{f}`.")
}
Ok(())
}