mirror of
https://github.com/l0ng-ai/tty7.git
synced 2026-09-21 16:02:20 +00:00
fix(file-tree): hand the copy its machine instead of letting it look one up
The same bug as the delete, one entry point over, and a lexical search for it missed this one: `file_tree_copy_into` looks the host up itself, and the drop-replace path calls it *after* asking whether to replace. A workspace repointed while that prompt is up would have put the files on the machine the window had by then. The host is now an argument, so the question of which machine cannot be answered late: the caller decides before it asks, and the direct drop — which never awaits — passes what it already had. Checked by walking every awaiting closure in the file: none look up a host after an await now. `sftp.rs` had the right shape all along, verifying its pane is still the open one before acting; it is the model for this.
This commit is contained in:
+15
-5
@@ -1406,11 +1406,20 @@ impl Tty7App {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.file_tree_copy_into(sources, dir, false, window, cx);
|
||||
let Some(host) = self.active_host(cx) else {
|
||||
return;
|
||||
};
|
||||
self.file_tree_copy_into(host, sources, dir, false, window, cx);
|
||||
}
|
||||
|
||||
/// `host` is handed in rather than looked up here, because one caller asks
|
||||
/// a question first and a workspace can be repointed at another machine
|
||||
/// while a prompt is up. Looking it up after the answer would put the files
|
||||
/// on whichever machine the window had by then; taking it as an argument
|
||||
/// makes the caller decide before it asks.
|
||||
fn file_tree_copy_into(
|
||||
&mut self,
|
||||
host: SharedHost,
|
||||
sources: Vec<PathBuf>,
|
||||
dir: PathBuf,
|
||||
overwrite: bool,
|
||||
@@ -1420,9 +1429,6 @@ impl Tty7App {
|
||||
if sources.is_empty() {
|
||||
return;
|
||||
}
|
||||
let Some(host) = self.active_host(cx) else {
|
||||
return;
|
||||
};
|
||||
let id = host.id();
|
||||
let asked_for = sources.clone();
|
||||
let target = dir.clone();
|
||||
@@ -1462,6 +1468,10 @@ impl Tty7App {
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
// Before the question, for the reason `file_tree_copy_into` gives.
|
||||
let Some(host) = self.active_host(cx) else {
|
||||
return;
|
||||
};
|
||||
let title = match conflicts.as_slice() {
|
||||
[one] => t_fmt(L10nKey::FileDropReplaceTitle, &[("name", one)]),
|
||||
many => t_fmt(
|
||||
@@ -1479,7 +1489,7 @@ impl Tty7App {
|
||||
cx.spawn_in(window, async move |app, cx| {
|
||||
let Ok(0) = answer.await else { return };
|
||||
let _ = app.update_in(cx, |app, window, cx| {
|
||||
app.file_tree_copy_into(sources, dir, true, window, cx);
|
||||
app.file_tree_copy_into(host, sources, dir, true, window, cx);
|
||||
});
|
||||
})
|
||||
.detach();
|
||||
|
||||
Reference in New Issue
Block a user