@@ 90,20 90,16 @@ impl User {
let open = |file: &str| -> Result<File> {
let mut path = path.clone();
path.push(file);
- let mut file = std::fs::OpenOptions::new()
- .append(true)
+ if path.exists() {
+ let mut old = path.clone();
+ old.set_extension("old");
+ std::fs::rename(&path, old)?;
+ }
+ let file = std::fs::OpenOptions::new()
+ .write(true)
.create(true)
.open(&path)
.with_context(|| anyhow!("Failed to open {}", &path.to_string_lossy()))?;
- // I wanted to write a timestamp here but the size:utility ratio of chronos was too
- // high. If I find more occasions to use timestamps, I'll come back to this.
- file.write_all(b"rstdm-----rstdm-----rstdm-----rstdm-----rstdm\n")
- .with_context(|| {
- anyhow!(
- "Got handle on {} but failed to write to it",
- path.to_string_lossy()
- )
- })?;
Ok(file)
};