mirror of
https://codeberg.org/postscriptum/snac2nex.git
synced 2026-03-31 21:25:28 +00:00
prevent ssd extra writes if the post file is up to date
This commit is contained in:
parent
6c5c158272
commit
9c835a9ec0
1 changed files with 14 additions and 1 deletions
15
src/nex.rs
15
src/nex.rs
|
|
@ -133,7 +133,20 @@ impl Nex {
|
||||||
.format(&self.filename.trim_matches(std::path::MAIN_SEPARATOR))
|
.format(&self.filename.trim_matches(std::path::MAIN_SEPARATOR))
|
||||||
.to_string(),
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue