Repository: rust-lang/mdBook (language: rust)

Issue:
Watch triggers multiple times for non-markdown on APFS (macOS)
### Problem

Editing non-`.md` files in the book's source folder triggers multiple rebuilds when using `mdbook serve`. The amount of rebuilds is not constant, I've seen it vary from 2 to over 20 times. Editing markdown files triggers a single rebuild.


### Steps

1. `cd $(mktemp -d)`
2. `mdbook init </dev/null`
3. `echo "export let lorem = 'ipsum';" > src/test.ts`
4. `echo -e '```\n{{#include test.ts}}\n```' >> src/chapter_1.md`
5. `mdbook serve`
6. in a second terminal: `touch src/test.ts`

<img width="1512" alt="terminal showing over a dozen rebuilds" src="https://github.com/rust-lang/mdBook/assets/821510/3d925d81-8c34-4b76-8fc9-a70472aede0d">


### Possible Solution(s)

Switching `notify` from `macos_fsevent` to `macos_kqueue` seems to fix the issue, triggering only a single rebuild whenever the `src/test.ts` file changes.



### Notes

This happens on an APFS drive on macOS. It doesn't happen on ext4 in a linux VM.

I'm not sure why this happens. A simple test using the following code doesn't trigger the multitude of events, leading me to think the cause lies within mdbook and not in notify.

```rust
use std::{path::Path, thread::sleep, time::Duration};

use notify::RecursiveMode;

fn main() {
    let mut debouncer =
        notify_debouncer_mini::new_debouncer(Duration::from_secs(1), None, |event| {
            println!("event {:#?}", event);
        })
        .unwrap();

    let watcher = debouncer.watcher();

    watcher
        .watch(Path::new("."), RecursiveMode::Recursive)
        .unwrap();

    loop {
        sleep(Duration::from_millis(500));
    }
}
```

### Version

```text
mdbook v0.4.32 (also happens on v0.4.31, earlier versions not tested)
```



Discussion / hints:
Hey, I think I found something.
It seems like the copy_files_except_ext on line 631 is causing the file to be picked up as changed.

<img width="1164" alt="image" src="https://github.com/rust-lang/mdBook/assets/4487942/35ece585-f4ed-48f6-a8d8-6cee188b3ff7">

If you comment this line out it only gets picked up once.

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 748861503b..be6dd5eed3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,7 +37,7 @@ toml = "0.7.6"
 topological-sort = "0.2.2"
 
 # Watch feature
-notify = { version = "6.0.1", optional = true }
+notify = { version = "6.0.1", optional = true, features = ["macos_kqueue"] }
 notify-debouncer-mini = { version = "0.3.0", optional = true }
 ignore = { version = "0.4.20", optional = true }
 


Test patch: