Rename entry atomically in LocalWorktree::rename
This commit is contained in:
parent
8fdc5c9be3
commit
a19766931d
1 changed files with 17 additions and 4 deletions
|
@ -628,7 +628,8 @@ impl LocalWorktree {
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
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 = refresh_entry(fs.as_ref(), &background_snapshot, path, &abs_path).await?;
|
let entry =
|
||||||
|
refresh_entry(fs.as_ref(), &background_snapshot, path, &abs_path, None).await?;
|
||||||
this.update(&mut cx, |this, cx| this.poll_snapshot(cx));
|
this.update(&mut cx, |this, cx| this.poll_snapshot(cx));
|
||||||
Ok((
|
Ok((
|
||||||
File {
|
File {
|
||||||
|
@ -684,7 +685,14 @@ impl LocalWorktree {
|
||||||
let fs = self.fs.clone();
|
let fs = self.fs.clone();
|
||||||
let save = cx.background().spawn(async move {
|
let save = cx.background().spawn(async move {
|
||||||
fs.save(&abs_path, &text).await?;
|
fs.save(&abs_path, &text).await?;
|
||||||
refresh_entry(fs.as_ref(), &background_snapshot, path.clone(), &abs_path).await
|
refresh_entry(
|
||||||
|
fs.as_ref(),
|
||||||
|
&background_snapshot,
|
||||||
|
path.clone(),
|
||||||
|
&abs_path,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
@ -709,12 +717,12 @@ impl LocalWorktree {
|
||||||
let rename = cx.background().spawn(async move {
|
let rename = cx.background().spawn(async move {
|
||||||
fs.rename(&abs_old_path, &abs_new_path, Default::default())
|
fs.rename(&abs_old_path, &abs_new_path, Default::default())
|
||||||
.await?;
|
.await?;
|
||||||
background_snapshot.lock().remove_path(&old_path);
|
|
||||||
refresh_entry(
|
refresh_entry(
|
||||||
fs.as_ref(),
|
fs.as_ref(),
|
||||||
&background_snapshot,
|
&background_snapshot,
|
||||||
new_path.clone(),
|
new_path.clone(),
|
||||||
&abs_new_path,
|
&abs_new_path,
|
||||||
|
Some(old_path),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
});
|
});
|
||||||
|
@ -2144,6 +2152,7 @@ async fn refresh_entry(
|
||||||
snapshot: &Mutex<LocalSnapshot>,
|
snapshot: &Mutex<LocalSnapshot>,
|
||||||
path: Arc<Path>,
|
path: Arc<Path>,
|
||||||
abs_path: &Path,
|
abs_path: &Path,
|
||||||
|
old_path: Option<Arc<Path>>,
|
||||||
) -> Result<Entry> {
|
) -> Result<Entry> {
|
||||||
let root_char_bag;
|
let root_char_bag;
|
||||||
let next_entry_id;
|
let next_entry_id;
|
||||||
|
@ -2160,7 +2169,11 @@ async fn refresh_entry(
|
||||||
&next_entry_id,
|
&next_entry_id,
|
||||||
root_char_bag,
|
root_char_bag,
|
||||||
);
|
);
|
||||||
Ok(snapshot.lock().insert_entry(entry, fs))
|
let mut snapshot = snapshot.lock();
|
||||||
|
if let Some(old_path) = old_path {
|
||||||
|
snapshot.remove_path(&old_path);
|
||||||
|
}
|
||||||
|
Ok(snapshot.insert_entry(entry, fs))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn char_bag_for_path(root_char_bag: CharBag, path: &Path) -> CharBag {
|
fn char_bag_for_path(root_char_bag: CharBag, path: &Path) -> CharBag {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue