refactor: the server, restore and the window's seams on the plain-folder backup; git removed from the store
Restore reads a destination folder, a set's folder, or a backup file with an optional passphrase; the server cuts the books under the store's lock and writes the folder outside it; the format upgrade proves a local backup in the book's folder (the same form) before it moves the format. The old backup (git processes, their locks, the output drain) and every test of it are gone; what each test protected is held by the new form's tests (table in the report). Old settings and an old history in a book's folder are said in the status and left alone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
9f4529b078
commit
a6cd89d2a6
35 files changed
+1150
-6636
No files matched your search
@@ -130,11 +130,30 @@ pub enum AgentStart {
|
||||
Missing(Installer),
|
||||
}
|
||||
|
||||
/// A passphrase typed into the window: never shown by `Debug`, wiped from
|
||||
/// memory when dropped.
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Secret(pub String);
|
||||
|
||||
impl std::fmt::Debug for Secret {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("Secret(…)")
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Secret {
|
||||
fn drop(&mut self) {
|
||||
zeroize::Zeroize::zeroize(&mut self.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// A restore previewed: what it would do, and what it is of (INVARIANT 3).
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct RestorePlan {
|
||||
/// The backup, as the server is told it.
|
||||
/// The backup, as the server is told it: a folder or a file.
|
||||
pub source: String,
|
||||
/// Its passphrase when it has one: never shown, wiped when dropped.
|
||||
pub passphrase: Option<Secret>,
|
||||
/// The books' id it comes back as.
|
||||
pub id: String,
|
||||
/// Whether it replaces the books of that id (kept in legacy/).
|
||||
@@ -441,6 +460,7 @@ pub trait Owner: Send + Sync {
|
||||
source: &str,
|
||||
id: Option<String>,
|
||||
replace: bool,
|
||||
passphrase: Option<Secret>,
|
||||
) -> Result<RestorePlan, String>;
|
||||
/// Restore as `plan` previewed it.
|
||||
fn restore(&self, plan: &RestorePlan) -> Result<Vec<String>, String>;
|
||||
@@ -632,6 +652,9 @@ struct RestoreForm {
|
||||
source: String,
|
||||
id: String,
|
||||
replace: bool,
|
||||
/// The backup's passphrase, if it has one (wiped when the form is
|
||||
/// dropped).
|
||||
passphrase: String,
|
||||
/// A check under way, and what it was asked (a result for anything
|
||||
/// since edited is dropped).
|
||||
planning: Option<Checking>,
|
||||
@@ -639,6 +662,13 @@ struct RestoreForm {
|
||||
problem: Option<String>,
|
||||
}
|
||||
|
||||
impl Drop for RestoreForm {
|
||||
/// What was typed and not handed over is wiped from memory.
|
||||
fn drop(&mut self) {
|
||||
zeroize::Zeroize::zeroize(&mut self.passphrase);
|
||||
}
|
||||
}
|
||||
|
||||
/// The menu's state: a dialog, the job under way, and the last outcome.
|
||||
#[derive(Default)]
|
||||
pub struct OwnerMenu {
|
||||
@@ -1114,7 +1144,7 @@ impl OwnerMenu {
|
||||
egui::Modal::new(self.scope.unwrap_or(egui::Id::NULL).with("owner-restore")).show(ctx, |ui| {
|
||||
ui.set_max_width(520.0);
|
||||
ui.heading("Restore books");
|
||||
ui.label("The backup: its repository's address, or its folder (the books' .git folder in your backup folder).");
|
||||
ui.label("The backup: your backup folder, the folder of one set of books in it, or a backup file (.wbbackup).");
|
||||
// Not changed while it is being checked.
|
||||
let open = form.planning.is_none();
|
||||
let edited = ui
|
||||
@@ -1122,9 +1152,21 @@ impl OwnerMenu {
|
||||
open,
|
||||
egui::TextEdit::singleline(&mut form.source)
|
||||
.desired_width(f32::INFINITY)
|
||||
.hint_text("/media/backup/acme.git, or git@host:you/books.git"),
|
||||
.hint_text("/media/backup, or /home/you/acme.wbbackup"),
|
||||
)
|
||||
.changed();
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Passphrase, if the backup has one");
|
||||
if ui
|
||||
.add_enabled(
|
||||
open,
|
||||
egui::TextEdit::singleline(&mut form.passphrase).password(true),
|
||||
)
|
||||
.changed()
|
||||
{
|
||||
form.plan = None;
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("As the books");
|
||||
let id_edited = ui
|
||||
@@ -1164,6 +1206,8 @@ impl OwnerMenu {
|
||||
if ui.add_enabled(ready, egui::Button::new("Check it")).clicked() {
|
||||
let (tx, rx) = channel();
|
||||
let (o, s, r) = (owner.clone(), form.source.clone(), form.replace);
|
||||
let pass = Some(Secret(form.passphrase.clone()))
|
||||
.filter(|p| !p.0.is_empty());
|
||||
let id = Some(form.id.trim().to_string()).filter(|i| !i.is_empty());
|
||||
let ctx = ui.ctx().clone();
|
||||
// Only reads the backup: stopped with its tab.
|
||||
@@ -1174,7 +1218,7 @@ impl OwnerMenu {
|
||||
if stop.requested() {
|
||||
return;
|
||||
}
|
||||
let _ = tx.send(o.plan_restore(&s, id, r));
|
||||
let _ = tx.send(o.plan_restore(&s, id, r, pass));
|
||||
ctx.request_repaint();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -264,7 +264,13 @@ impl Owner for Fake {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
|
||||
@@ -34,7 +34,13 @@ impl Owner for Fake {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
|
||||
@@ -91,6 +91,7 @@ impl Owner for Fake {
|
||||
_source: &str,
|
||||
_id: Option<String>,
|
||||
_replace: bool,
|
||||
_passphrase: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not in these tests".into())
|
||||
}
|
||||
|
||||
@@ -80,7 +80,13 @@ impl Owner for Held {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
|
||||
@@ -48,11 +48,13 @@ impl Owner for Fake {
|
||||
source: &str,
|
||||
id: Option<String>,
|
||||
replace: bool,
|
||||
passphrase: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
std::thread::sleep(std::time::Duration::from_millis(300));
|
||||
self.said(format!("plan {source} {id:?} {replace}"));
|
||||
Ok(RestorePlan {
|
||||
source: source.to_string(),
|
||||
passphrase,
|
||||
id: id.unwrap_or_else(|| "acme".into()),
|
||||
replace,
|
||||
head: (7, "ab".repeat(32)),
|
||||
@@ -220,7 +222,7 @@ fn the_books_menu_hands_each_action_to_the_owner_and_writes_nothing() {
|
||||
h.get_all_by_role(egui::accesskit::Role::TextInput)
|
||||
.nth(page_fields)
|
||||
.unwrap()
|
||||
.type_text("/media/disk/acme.git");
|
||||
.type_text("/media/disk/backups");
|
||||
h.run_steps(2);
|
||||
assert!(
|
||||
h.query_by_label("Restore it").is_none(),
|
||||
@@ -230,7 +232,7 @@ fn the_books_menu_hands_each_action_to_the_owner_and_writes_nothing() {
|
||||
settle(&mut h, &f, start + 3);
|
||||
assert_eq!(
|
||||
f.asked.lock().unwrap()[start + 2],
|
||||
"plan /media/disk/acme.git None false"
|
||||
"plan /media/disk/backups None false"
|
||||
);
|
||||
assert!(
|
||||
h.query_by_label_contains("is whole: through event 7")
|
||||
@@ -240,7 +242,7 @@ fn the_books_menu_hands_each_action_to_the_owner_and_writes_nothing() {
|
||||
settle(&mut h, &f, start + 4);
|
||||
assert_eq!(
|
||||
f.asked.lock().unwrap()[start + 3],
|
||||
"restore /media/disk/acme.git acme 7"
|
||||
"restore /media/disk/backups acme 7"
|
||||
);
|
||||
|
||||
// There is no "Close the books": a company's tab, or the window, closes
|
||||
@@ -307,7 +309,7 @@ fn nothing_is_changed_while_it_is_at_work() {
|
||||
h.get_all_by_role(egui::accesskit::Role::TextInput)
|
||||
.nth(page_fields)
|
||||
.unwrap()
|
||||
.type_text("/media/disk/acme.git");
|
||||
.type_text("/media/disk/backups");
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Check it").click();
|
||||
h.run_steps(2);
|
||||
@@ -390,7 +392,7 @@ fn screenshots() {
|
||||
h.get_all_by_role(egui::accesskit::Role::TextInput)
|
||||
.nth(page_fields)
|
||||
.unwrap()
|
||||
.type_text("/media/disk/acme.git");
|
||||
.type_text("/media/disk/backups");
|
||||
shot(&mut h, "restore-ask");
|
||||
h.get_by_label("Check it").click();
|
||||
let n = f.asked.lock().unwrap().len();
|
||||
|
||||
@@ -179,7 +179,13 @@ impl Owner for Fake {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
@@ -464,7 +470,13 @@ fn a_window_with_no_server_asks_nothing_of_any() {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
|
||||
@@ -42,7 +42,13 @@ impl Owner for Quiet {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
|
||||
@@ -585,7 +585,13 @@ impl Owner for Agentic {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
@@ -2105,9 +2111,11 @@ impl Owner for Gated {
|
||||
source: &str,
|
||||
id: Option<String>,
|
||||
replace: bool,
|
||||
passphrase: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Ok(RestorePlan {
|
||||
source: source.to_string(),
|
||||
passphrase,
|
||||
id: id.unwrap_or_else(|| "alpha".into()),
|
||||
replace,
|
||||
head: (7, "ab".repeat(32)),
|
||||
|
||||
@@ -40,7 +40,13 @@ impl Owner for Fake {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not in these tests".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not in these tests".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
|
||||
@@ -183,6 +183,7 @@ impl Owner for Web {
|
||||
_source: &str,
|
||||
_id: Option<String>,
|
||||
_replace: bool,
|
||||
_passphrase: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
|
||||
@@ -47,7 +47,13 @@ impl Owner for Fake {
|
||||
fn back_up_now(&self, _: &str) -> Result<Vec<String>, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn plan_restore(&self, _: &str, _: Option<String>, _: bool) -> Result<RestorePlan, String> {
|
||||
fn plan_restore(
|
||||
&self,
|
||||
_: &str,
|
||||
_: Option<String>,
|
||||
_: bool,
|
||||
_: Option<ledger_gui::owner::Secret>,
|
||||
) -> Result<RestorePlan, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
fn restore(&self, _: &RestorePlan) -> Result<Vec<String>, String> {
|
||||
|
||||
Reference in new issue
Block a user