feat: the window and the command line set up, save and show backups; the system's folder dialog
Admin requests set up the backup folder (journaled as the books' own backup.folder setting, the owner the one who decided) and the passphrase, save a backup as one file, and say how the backups stand; the Backups window, Save a backup and Restore (a folder or a file, with the passphrase when it has one) use them, and the command line has backup-setup, backup-status and backup-save (the passphrase typed at a terminal, never on the command line). New dependency: rfd (MIT) in ledger-gui, with pollster, for the system's own folder and file dialogs (the portal on Linux, native on Windows and macOS). It adds no other crate to the tree (zbus is already there through the window toolkit); cargo deny passes and THIRD-PARTY-NOTICES.txt is regenerated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
0720f3036d
commit
51a7607a82
11 files changed
+1214
-3
No files matched your search
@@ -1656,6 +1656,53 @@ impl Books {
|
||||
Err(why) => Response::Refused(self.hide(why)),
|
||||
}
|
||||
}
|
||||
Request::BackupSetup {
|
||||
id,
|
||||
folder,
|
||||
passphrase,
|
||||
remove_passphrase,
|
||||
} => match self.backups_of(&id) {
|
||||
Ok(backups) => {
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let pass = passphrase.as_ref().map(|p| p.0.clone());
|
||||
match rt.block_on(backups.set_up(folder, pass, remove_passphrase)) {
|
||||
Ok(lines) => Response::Said { lines },
|
||||
Err(why) => Response::Refused(self.hide(why)),
|
||||
}
|
||||
}
|
||||
Err(r) => r,
|
||||
},
|
||||
Request::BackupStatus { id } => match self.backups_of(&id) {
|
||||
Ok(backups) => {
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let s = rt.block_on(backups.window_standing());
|
||||
let t = s.status.targets.first();
|
||||
Response::BackupStatus(admin::BackupStanding {
|
||||
head_seq: s.status.head_seq,
|
||||
folder: s.folder,
|
||||
sealed: s.sealed,
|
||||
last_ok_at: t.and_then(|t| t.last_ok_at.clone()),
|
||||
through_seq: t.and_then(|t| t.through_seq),
|
||||
stale: t.is_some_and(|t| t.stale),
|
||||
last_error: t.and_then(|t| t.last_error.clone()),
|
||||
last_drill_at: t.and_then(|t| t.last_drill_at.clone()),
|
||||
drill_error: t.and_then(|t| t.drill_error.clone()),
|
||||
disconnected: t.is_some_and(|t| t.disconnected),
|
||||
note: s.status.note,
|
||||
})
|
||||
}
|
||||
Err(r) => r,
|
||||
},
|
||||
Request::BackupSave { id, path } => match self.backups_of(&id) {
|
||||
Ok(backups) => {
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
match rt.block_on(backups.save_file(&path)) {
|
||||
Ok(lines) => Response::Said { lines },
|
||||
Err(why) => Response::Refused(self.hide(why)),
|
||||
}
|
||||
}
|
||||
Err(r) => r,
|
||||
},
|
||||
Request::Adopt {
|
||||
id,
|
||||
source,
|
||||
@@ -2180,6 +2227,22 @@ impl Books {
|
||||
)
|
||||
}
|
||||
|
||||
/// The backups of the open book `id`, or the refusal to give a request
|
||||
/// that needs them.
|
||||
fn backups_of(&self, id: &str) -> Result<Arc<crate::backup::Backups>, Response> {
|
||||
let refused = |text: String| Response::Refused(self.hide(text));
|
||||
let id = BookId::parse(id).map_err(|e| refused(e.to_string()))?;
|
||||
match self.held().get(id.as_str()) {
|
||||
Some(Book::Open { backups, .. }) => Ok(backups.clone()),
|
||||
Some(Book::Failed(why)) => Err(refused(format!("those books didn't open: {why}"))),
|
||||
Some(Book::Closed) => Err(refused(self.not_open(&id))),
|
||||
None => Err(refused(format!(
|
||||
"there are no books called {:?}",
|
||||
id.as_str()
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
/// What is said of a book that exists but isn't open, to an admin
|
||||
/// request that needs it open.
|
||||
fn not_open(&self, id: &BookId) -> String {
|
||||
|
||||
Reference in new issue
Block a user