Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Spaces S0: write the pre-spaces backup under .partial and rename when complete

Lin (kwant bot)ee7db6f1cdae
diff --git a/src/db/spaces.rs b/src/db/spaces.rs
index 1b6fe815..9120cbb9 100644
--- a/src/db/spaces.rs
+++ b/src/db/spaces.rs
@@ -169,11 +169,16 @@ impl Database {
path = dir.join(format!("kwnt-pre-spaces-{stamp}-{n}.db"));
n += 1;
}
+ // Write under a `.partial` name and rename once complete, so a kill mid-copy never
+ // leaves a truncated file that looks like a real backup.
+ let partial = path.with_extension("db.partial");
+ let _ = std::fs::remove_file(&partial);
sqlx::query("VACUUM INTO ?")
- .bind(path.to_string_lossy().into_owned())
+ .bind(partial.to_string_lossy().into_owned())
.execute(&self.pool)
.await?;
- restrict(&path, 0o600)?;
+ restrict(&partial, 0o600)?;
+ std::fs::rename(&partial, &path)?;
Ok(path)
}
}