diff --git a/src/nex.rs b/src/nex.rs index 59d7204..7abf431 100644 --- a/src/nex.rs +++ b/src/nex.rs @@ -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(()) }