Don't panic if worktree was dropped before sending path changes

In `refresh_entry`, we send a message to the `self.path_changes_tx` channel
to notify the background thread that a path has changed. However, given that
`refresh_entry` uses `spawn_weak`, the worktree could get dropped before sending
the message, which could cause a panic.

This commit changes the code to return an error instead of panicking.
This commit is contained in:
Antonio Scandurra 2023-04-10 08:16:08 +02:00
parent 035189a2a1
commit 372e31d54f

View file

@ -838,8 +838,7 @@ impl LocalWorktree {
.unwrap() .unwrap()
.path_changes_tx .path_changes_tx
.try_send((vec![abs_path], tx)) .try_send((vec![abs_path], tx))
.unwrap(); })?;
});
rx.recv().await; rx.recv().await;
Ok(()) Ok(())
})) }))
@ -930,7 +929,7 @@ impl LocalWorktree {
} }
let (tx, mut rx) = barrier::channel(); let (tx, mut rx) = barrier::channel();
path_changes_tx.try_send((paths, tx)).unwrap(); path_changes_tx.try_send((paths, tx))?;
rx.recv().await; rx.recv().await;
this.upgrade(&cx) this.upgrade(&cx)
.ok_or_else(|| anyhow!("worktree was dropped"))? .ok_or_else(|| anyhow!("worktree was dropped"))?