diff --git a/crates/tty7-cli/src/commands.rs b/crates/tty7-cli/src/commands.rs index 10b88fc3..ce9b8d04 100644 --- a/crates/tty7-cli/src/commands.rs +++ b/crates/tty7-cli/src/commands.rs @@ -772,7 +772,10 @@ fn adopt_pane( } /// The workspace a pane was spawned for, if it is still on this machine. -fn owner_of(info: &tty7_core::daemon::protocol::PaneInfo, machine: &Machine) -> Option { +fn owner_of( + info: &tty7_core::daemon::protocol::PaneInfo, + machine: &Machine, +) -> Option { let owner = info.owner.as_deref()?; machine .workspaces @@ -2201,7 +2204,9 @@ mod tests { .push_back(ReplyOk::TabTree(Box::new(Tab::leaf(37)))); run_cli( - &["tty7", "tab", "new", "web", "--pane", "%37", "--cwd", "C:\\else"], + &[ + "tty7", "tab", "new", "web", "--pane", "%37", "--cwd", "C:\\else", + ], &Context::default(), &mut backend, ); diff --git a/crates/tty7-core/src/core/machine.rs b/crates/tty7-core/src/core/machine.rs index 5479709c..2a0fdb29 100644 --- a/crates/tty7-core/src/core/machine.rs +++ b/crates/tty7-core/src/core/machine.rs @@ -1304,12 +1304,9 @@ fn backup_path(path: &Path, generation: usize) -> PathBuf { /// Returns `Ok(())` when there was nothing to do: no tree yet, or the newest /// generation is younger than `spacing`. fn keep_a_generation(path: &Path, spacing: Duration) -> io::Result<()> { - let bytes = match std::fs::read(path) { - Ok(bytes) => bytes, - // Nothing has been written yet, so there is no previous generation. - Err(e) if e.kind() == io::ErrorKind::NotFound => return Ok(()), - Err(e) => return Err(e), - }; + // Asked before the tree is read: this runs on every persist and answers + // "nothing to do" on almost all of them, so reading the whole document + // first would be a full read per write for one copy every five minutes. let newest = backup_path(path, 0); let too_soon = std::fs::metadata(&newest) .and_then(|meta| meta.modified()) @@ -1318,6 +1315,12 @@ fn keep_a_generation(path: &Path, spacing: Duration) -> io::Result<()> { if too_soon { return Ok(()); } + let bytes = match std::fs::read(path) { + Ok(bytes) => bytes, + // Nothing has been written yet, so there is no previous generation. + Err(e) if e.kind() == io::ErrorKind::NotFound => return Ok(()), + Err(e) => return Err(e), + }; // Oldest first, so nothing is overwritten before it has been moved down. // A generation that is not there yet simply has nothing to move. for generation in (1..BACKUP_GENERATIONS).rev() { @@ -2701,8 +2704,12 @@ mod tests { let store = MachineStore::open(&path); let ws = store.workspace_create(None, None, None).unwrap(); - store.tab_create(ws.id, None, seed(1, "/work"), None, None).unwrap(); - store.tab_create(ws.id, None, seed(2, "/work"), None, None).unwrap(); + store + .tab_create(ws.id, None, seed(1, "/work"), None, None) + .unwrap(); + store + .tab_create(ws.id, None, seed(2, "/work"), None, None) + .unwrap(); let kept = backup_path(&path, 0); assert!( diff --git a/src/ui/tree_sync.rs b/src/ui/tree_sync.rs index 524e1b60..be7f0ef3 100644 --- a/src/ui/tree_sync.rs +++ b/src/ui/tree_sync.rs @@ -2909,7 +2909,8 @@ mod tests { assert_eq!(parked.name, "deploy"); assert_eq!( parked.workspace, ws, - "and it is parked against the workspace it was typed for, so a window that walks into a different one cannot spend it (#716)" + "and it is parked against the workspace it was typed for, so a window \ + that walks into a different one cannot spend it (#716)" ); }); }