Fix DB lock error: clear message + instructions, fix passphrase reprompt

Storage:
- Detects sled lock contention, shows actionable error:
  "Database locked by another warzone process"
  with ps command to find the process and rm command to force unlock

TUI:
- Poll loop no longer calls load_seed() (was re-prompting passphrase)
- Seed passed from main.rs to run_tui to poll_loop
- Single passphrase prompt per app launch

Warnings fixed:
- Removed unused `Context` import in tui/app.rs
- Added #[allow(dead_code)] on validate_token (used when auth middleware wired)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-27 08:24:53 +04:00
parent c8b51fa96b
commit d7b71efdbc
4 changed files with 28 additions and 6 deletions

View File

@@ -14,7 +14,25 @@ pub struct LocalDb {
impl LocalDb {
pub fn open() -> Result<Self> {
let path = crate::keystore::data_dir().join("db");
let db = sled::open(&path).context("failed to open local database")?;
let db = match sled::open(&path) {
Ok(db) => db,
Err(e) => {
let err_str = e.to_string();
if err_str.contains("WouldBlock") || err_str.contains("lock") {
eprintln!("Error: Database is locked by another warzone process.");
eprintln!(" DB path: {}", path.display());
eprintln!();
eprintln!(" Check for running processes:");
eprintln!(" ps aux | grep warzone-client");
eprintln!();
eprintln!(" To force unlock (if no other process is running):");
eprintln!(" rm -rf {}", path.display());
eprintln!(" (This deletes sessions — you'll need to re-establish them)");
anyhow::bail!("database locked by another process");
}
return Err(e).context("failed to open local database");
}
};
let sessions = db.open_tree("sessions")?;
let pre_keys = db.open_tree("pre_keys")?;
Ok(LocalDb {