Skip to content

Commit 54df581

Browse files
authored
windows: Add some trace-level logging to help dig into missing FS update bugs (#40200)
Related to #38109 Release Notes: - N/A
1 parent 0d84651 commit 54df581

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

crates/fs/src/fs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ impl Fs for RealFs {
749749
events
750750
.into_iter()
751751
.map(|event| {
752+
log::trace!("fs path event: {event:?}");
752753
let kind = if event.flags.contains(StreamFlags::ITEM_REMOVED) {
753754
Some(PathEventKind::Removed)
754755
} else if event.flags.contains(StreamFlags::ITEM_CREATED) {
@@ -806,6 +807,7 @@ impl Fs for RealFs {
806807

807808
// Check if path is a symlink and follow the target parent
808809
if let Some(mut target) = self.read_link(path).await.ok() {
810+
log::trace!("watch symlink {path:?} -> {target:?}");
809811
// Check if symlink target is relative path, if so make it absolute
810812
if target.is_relative()
811813
&& let Some(parent) = path.parent()

crates/fs/src/fs_watcher.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl Drop for FsWatcher {
4646

4747
impl Watcher for FsWatcher {
4848
fn add(&self, path: &std::path::Path) -> anyhow::Result<()> {
49+
log::trace!("watcher add: {path:?}");
4950
let tx = self.tx.clone();
5051
let pending_paths = self.pending_path_events.clone();
5152

@@ -63,11 +64,15 @@ impl Watcher for FsWatcher {
6364
.next_back()
6465
&& path.starts_with(watched_path.as_ref())
6566
{
67+
log::trace!(
68+
"path to watch is covered by existing registration: {path:?}, {watched_path:?}"
69+
);
6670
return Ok(());
6771
}
6872
}
6973
#[cfg(target_os = "linux")]
7074
{
75+
log::trace!("path to watch is already watched: {path:?}");
7176
if self.registrations.lock().contains_key(path) {
7277
return Ok(());
7378
}
@@ -85,6 +90,7 @@ impl Watcher for FsWatcher {
8590
let path = path.clone();
8691
|g| {
8792
g.add(path, mode, move |event: &notify::Event| {
93+
log::trace!("watcher received event: {event:?}");
8894
let kind = match event.kind {
8995
EventKind::Create(_) => Some(PathEventKind::Created),
9096
EventKind::Modify(_) => Some(PathEventKind::Changed),
@@ -126,6 +132,7 @@ impl Watcher for FsWatcher {
126132
}
127133

128134
fn remove(&self, path: &std::path::Path) -> anyhow::Result<()> {
135+
log::trace!("remove watched path: {path:?}");
129136
let Some(registration) = self.registrations.lock().remove(path) else {
130137
return Ok(());
131138
};
@@ -215,6 +222,7 @@ static FS_WATCHER_INSTANCE: OnceLock<anyhow::Result<GlobalWatcher, notify::Error
215222
OnceLock::new();
216223

217224
fn handle_event(event: Result<notify::Event, notify::Error>) {
225+
log::trace!("global handle event: {event:?}");
218226
// Filter out access events, which could lead to a weird bug on Linux after upgrading notify
219227
// https://github.com/zed-industries/zed/actions/runs/14085230504/job/39449448832
220228
let Some(event) = event

crates/fs/src/mac_watcher.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ impl MacWatcher {
3232

3333
impl Watcher for MacWatcher {
3434
fn add(&self, path: &Path) -> Result<()> {
35+
log::trace!("mac watcher add: {:?}", path);
3536
let handles = self
3637
.handles
3738
.upgrade()
@@ -44,6 +45,9 @@ impl Watcher for MacWatcher {
4445
.next_back()
4546
&& path.starts_with(watched_path)
4647
{
48+
log::trace!(
49+
"mac watched path starts with existing watched path: {watched_path:?}, {path:?}"
50+
);
4751
return Ok(());
4852
}
4953

crates/worktree/src/worktree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,7 @@ impl LocalSnapshot {
24392439
}
24402440

24412441
fn insert_entry(&mut self, mut entry: Entry, fs: &dyn Fs) -> Entry {
2442+
log::trace!("insert entry {:?}", entry.path);
24422443
if entry.is_file() && entry.path.file_name() == Some(&GITIGNORE) {
24432444
let abs_path = self.absolutize(&entry.path);
24442445
match smol::block_on(build_gitignore(&abs_path, fs)) {
@@ -3769,6 +3770,7 @@ impl BackgroundScanner {
37693770
}
37703771

37713772
async fn process_events(&self, mut abs_paths: Vec<PathBuf>) {
3773+
log::trace!("process events: {abs_paths:?}");
37723774
let root_path = self.state.lock().snapshot.abs_path.clone();
37733775
let root_canonical_path = self.fs.canonicalize(root_path.as_path()).await;
37743776
let root_canonical_path = match &root_canonical_path {
@@ -4368,7 +4370,6 @@ impl BackgroundScanner {
43684370
// detected regardless of the order of the paths.
43694371
for (path, metadata) in relative_paths.iter().zip(metadata.iter()) {
43704372
if matches!(metadata, Ok(None)) || doing_recursive_update {
4371-
log::trace!("remove path {:?}", path);
43724373
state.remove_path(path);
43734374
}
43744375
}

0 commit comments

Comments
 (0)