Grab share state after retrieving metadata when refreshing entry

This commit is contained in:
Antonio Scandurra 2022-05-16 11:46:49 +02:00
parent 576656ccf2
commit b144995f27

View file

@ -616,8 +616,10 @@ impl LocalWorktree {
let text = fs.load(&abs_path).await?; let text = fs.load(&abs_path).await?;
// Eagerly populate the snapshot with an updated entry for the loaded file // Eagerly populate the snapshot with an updated entry for the loaded file
let entry = this let entry = this
.update(&mut cx, |this, _| { .update(&mut cx, |this, cx| {
this.as_local().unwrap().refresh_entry(path, abs_path, None) this.as_local()
.unwrap()
.refresh_entry(path, abs_path, None, cx)
}) })
.await?; .await?;
this.update(&mut cx, |this, cx| this.poll_snapshot(cx)); this.update(&mut cx, |this, cx| this.poll_snapshot(cx));
@ -753,11 +755,12 @@ impl LocalWorktree {
Some(cx.spawn(|this, mut cx| async move { Some(cx.spawn(|this, mut cx| async move {
rename.await?; rename.await?;
let entry = this let entry = this
.update(&mut cx, |this, _| { .update(&mut cx, |this, cx| {
this.as_local_mut().unwrap().refresh_entry( this.as_local_mut().unwrap().refresh_entry(
new_path.clone(), new_path.clone(),
abs_new_path, abs_new_path,
Some(old_path), Some(old_path),
cx,
) )
}) })
.await?; .await?;
@ -793,10 +796,10 @@ impl LocalWorktree {
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
write.await?; write.await?;
let entry = this let entry = this
.update(&mut cx, |this, _| { .update(&mut cx, |this, cx| {
this.as_local_mut() this.as_local_mut()
.unwrap() .unwrap()
.refresh_entry(path, abs_path, None) .refresh_entry(path, abs_path, None, cx)
}) })
.await?; .await?;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
@ -813,18 +816,17 @@ impl LocalWorktree {
path: Arc<Path>, path: Arc<Path>,
abs_path: PathBuf, abs_path: PathBuf,
old_path: Option<Arc<Path>>, old_path: Option<Arc<Path>>,
) -> impl Future<Output = Result<Entry>> { cx: &mut ModelContext<Worktree>,
) -> Task<Result<Entry>> {
let fs = self.fs.clone();
let root_char_bag; let root_char_bag;
let next_entry_id; let next_entry_id;
let fs = self.fs.clone();
let shared_snapshots_tx = self.share.as_ref().map(|share| share.snapshots_tx.clone());
let snapshot = self.background_snapshot.clone();
{ {
let snapshot = snapshot.lock(); let snapshot = self.background_snapshot.lock();
root_char_bag = snapshot.root_char_bag; root_char_bag = snapshot.root_char_bag;
next_entry_id = snapshot.next_entry_id.clone(); next_entry_id = snapshot.next_entry_id.clone();
} }
async move { cx.spawn_weak(|this, cx| async move {
let entry = Entry::new( let entry = Entry::new(
path, path,
&fs.metadata(&abs_path) &fs.metadata(&abs_path)
@ -833,17 +835,28 @@ impl LocalWorktree {
&next_entry_id, &next_entry_id,
root_char_bag, root_char_bag,
); );
let mut snapshot = snapshot.lock();
let (entry, snapshot, snapshots_tx) = this
.upgrade(&cx)
.ok_or_else(|| anyhow!("worktree was dropped"))?
.read_with(&cx, |this, _| {
let this = this.as_local().unwrap();
let mut snapshot = this.background_snapshot.lock();
if let Some(old_path) = old_path { if let Some(old_path) = old_path {
snapshot.remove_path(&old_path); snapshot.remove_path(&old_path);
} }
let entry = snapshot.insert_entry(entry, fs.as_ref()); let entry = snapshot.insert_entry(entry, fs.as_ref());
snapshot.scan_id += 1; snapshot.scan_id += 1;
if let Some(tx) = shared_snapshots_tx { let snapshots_tx = this.share.as_ref().map(|s| s.snapshots_tx.clone());
tx.send(snapshot.clone()).await.ok(); (entry, snapshot.clone(), snapshots_tx)
});
if let Some(snapshots_tx) = snapshots_tx {
snapshots_tx.send(snapshot).await.ok();
} }
Ok(entry) Ok(entry)
} })
} }
pub fn register( pub fn register(