Use flush_fs_events more after performing synchronous fs mutations

I am not sure I have caught all the examples of this, but in general
I think we always want to perform a `flush_fs_events` as opposed to
`next_scan_complete` when doing synchronous I/O. Indeed, the file
system may inform us about the events caused by the just-performed
I/O over multiple batches, and `next_scan_complete` may return
before seeing all of them.

Note that this also removes a few assertions which were ensuring
that, on start, a worktree's file handle wouldn't know its deleted
status, even if the file didn't exist for sure on disk. However,
now that `file` is an async API, it's possible that by the time the
`FileHandle` is resolved, `Worktree` has already completed scanning.
We test a similar behavior further along in the test where those
assertions were removed, so it felt okay to proceed without them.
This commit is contained in:
Antonio Scandurra
2021-05-13 10:25:16 +02:00
parent 0187b6da2c
commit eea9cb47fd
2 changed files with 13 additions and 33 deletions
+4 -7
View File
@@ -3148,8 +3148,7 @@ mod tests {
});
fs::remove_file(dir.path().join("file2")).unwrap();
tree.update(&mut app, |tree, ctx| tree.next_scan_complete(ctx))
.await;
tree.flush_fs_events(&app).await;
assert_eq!(
*events.borrow(),
&[Event::Dirtied, Event::FileHandleChanged]
@@ -3174,8 +3173,7 @@ mod tests {
});
events.borrow_mut().clear();
fs::remove_file(dir.path().join("file3")).unwrap();
tree.update(&mut app, |tree, ctx| tree.next_scan_complete(ctx))
.await;
tree.flush_fs_events(&app).await;
assert_eq!(*events.borrow(), &[Event::FileHandleChanged]);
app.read(|ctx| assert!(buffer3.read(ctx).is_dirty()));
});
@@ -3218,14 +3216,13 @@ mod tests {
// Change the file on disk, adding two new lines of text, and removing
// one line.
buffer.update(&mut app, |buffer, _| {
buffer.read_with(&app, |buffer, _| {
assert!(!buffer.is_dirty());
assert!(!buffer.has_conflict());
});
tree.flush_fs_events(&app).await;
let new_contents = "AAAA\naaa\nBB\nbbbbb\n";
fs::write(&abs_path, new_contents).unwrap();
tree.flush_fs_events(&app).await;
// Because the buffer was not modified, it is reloaded from disk. Its
// contents are edited according to the diff between the old and new