From 9c835a9ec01b395f3123134c1cf44f4af66d714d Mon Sep 17 00:00:00 2001 From: postscriptum Date: Tue, 1 Jul 2025 22:26:18 +0300 Subject: [PATCH] prevent ssd extra writes if the post file is up to date --- src/nex.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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(()) }