Dependency update: update notify version to v5 (#8114)

# Description

Relative: #8060

While investigating, I found we need to update notify, which is a good
step to remove some duplicate dependencies.

As title, here are some goods and bads after updating:

## Good
keep dependency up to date, and remove duplidate dependency(cfg-if,
winapi) in Cargo.lock.

## Bad
Introduce some breaking changes:
After updating to notify v5, I found that we have to remove `Rename`
events.

But I've testing under notify v4, and it doesn't work good if we running
the following command on MacOS:
```
touch a
mv a b
```
It fires file create event, but no file rename event. So `rename` event
is not really reliable, so I think it's ok for us to remove `Rename`
events.

The reason to remove `--debounce-ms` flag:
It's not provided by defualt file watcher, we can use
[PollWatcher](https://docs.rs/notify/latest/notify/poll/struct.PollWatcher.html),
but it scans filesystem, which is really expensive. So I just remove the
flag.

# User-Facing Changes

1. `--debounce-ms` flag is removed
2. no longer watch `Rename` event.

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
WindSoilder 2023-02-23 05:35:09 +08:00 committed by GitHub
parent fc23c6721a
commit 0e86ba4b63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 159 additions and 310 deletions

291
Cargo.lock generated
View file

@ -35,7 +35,7 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "464b3811b747f8f7ebc8849c9c728c39f6ac98a055edad93baf9eb330e3f8f9d" checksum = "464b3811b747f8f7ebc8849c9c728c39f6ac98a055edad93baf9eb330e3f8f9d"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"const-random", "const-random",
"getrandom 0.2.7", "getrandom 0.2.7",
"once_cell", "once_cell",
@ -245,7 +245,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi",
"libc", "libc",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -497,12 +497,6 @@ dependencies = [
"nom", "nom",
] ]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -523,7 +517,7 @@ dependencies = [
"serde", "serde",
"time 0.1.44", "time 0.1.44",
"wasm-bindgen", "wasm-bindgen",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -648,7 +642,7 @@ dependencies = [
"libc", "libc",
"terminal_size 0.1.17", "terminal_size 0.1.17",
"unicode-width", "unicode-width",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -742,7 +736,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
] ]
[[package]] [[package]]
@ -788,7 +782,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95da181745b56d4bd339530ec393508910c909c784e8962d15d722bacf0bcbcd" checksum = "95da181745b56d4bd339530ec393508910c909c784e8962d15d722bacf0bcbcd"
dependencies = [ dependencies = [
"bare-metal 1.0.0", "bare-metal 1.0.0",
"cfg-if 1.0.0", "cfg-if",
"cortex-m", "cortex-m",
"riscv", "riscv",
] ]
@ -799,7 +793,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"crossbeam-utils", "crossbeam-utils",
] ]
@ -809,7 +803,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"crossbeam-epoch", "crossbeam-epoch",
"crossbeam-utils", "crossbeam-utils",
] ]
@ -821,7 +815,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"cfg-if 1.0.0", "cfg-if",
"crossbeam-utils", "crossbeam-utils",
"memoffset", "memoffset",
"scopeguard", "scopeguard",
@ -833,7 +827,7 @@ version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
] ]
[[package]] [[package]]
@ -845,12 +839,12 @@ dependencies = [
"bitflags", "bitflags",
"crossterm_winapi", "crossterm_winapi",
"libc", "libc",
"mio 0.8.4", "mio",
"parking_lot 0.12.1", "parking_lot 0.12.1",
"serde", "serde",
"signal-hook", "signal-hook",
"signal-hook-mio", "signal-hook-mio",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -862,11 +856,11 @@ dependencies = [
"bitflags", "bitflags",
"crossterm_winapi", "crossterm_winapi",
"libc", "libc",
"mio 0.8.4", "mio",
"parking_lot 0.12.1", "parking_lot 0.12.1",
"signal-hook", "signal-hook",
"signal-hook-mio", "signal-hook-mio",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -875,7 +869,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c"
dependencies = [ dependencies = [
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -970,7 +964,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d91974fbbe88ec1df0c24a4f00f99583667a7e2e6272b2b92d294d81e462173" checksum = "1d91974fbbe88ec1df0c24a4f00f99583667a7e2e6272b2b92d294d81e462173"
dependencies = [ dependencies = [
"nix", "nix",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -985,7 +979,7 @@ version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"hashbrown 0.12.3", "hashbrown 0.12.3",
"lock_api", "lock_api",
"once_cell", "once_cell",
@ -1052,7 +1046,7 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"dirs-sys-next", "dirs-sys-next",
] ]
@ -1064,7 +1058,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [ dependencies = [
"libc", "libc",
"redox_users", "redox_users",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -1075,7 +1069,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [ dependencies = [
"libc", "libc",
"redox_users", "redox_users",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -1166,7 +1160,7 @@ version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
] ]
[[package]] [[package]]
@ -1208,7 +1202,7 @@ checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [ dependencies = [
"errno-dragonfly", "errno-dragonfly",
"libc", "libc",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -1275,7 +1269,7 @@ version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e11dcc7e4d79a8c89b9ab4c6f5c30b1fc4a83c420792da3542fd31179ed5f517" checksum = "e11dcc7e4d79a8c89b9ab4c6f5c30b1fc4a83c420792da3542fd31179ed5f517"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"rustix", "rustix",
"windows-sys 0.36.1", "windows-sys 0.36.1",
] ]
@ -1286,7 +1280,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12d741e2415d4e2e5bd1c1d00409d1a8865a57892c2d689b504365655d237d43" checksum = "12d741e2415d4e2e5bd1c1d00409d1a8865a57892c2d689b504365655d237d43"
dependencies = [ dependencies = [
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -1295,7 +1289,7 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c" checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"libc", "libc",
"redox_syscall", "redox_syscall",
"windows-sys 0.36.1", "windows-sys 0.36.1",
@ -1362,41 +1356,15 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]]
name = "fsevent"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6"
dependencies = [
"bitflags",
"fsevent-sys",
]
[[package]] [[package]]
name = "fsevent-sys" name = "fsevent-sys"
version = "2.0.1" version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
dependencies = [ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
dependencies = [
"bitflags",
"fuchsia-zircon-sys",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]] [[package]]
name = "futf" name = "futf"
version = "0.1.5" version = "0.1.5"
@ -1530,7 +1498,7 @@ version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"libc", "libc",
"wasi 0.9.0+wasi-snapshot-preview1", "wasi 0.9.0+wasi-snapshot-preview1",
] ]
@ -1541,7 +1509,7 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"js-sys", "js-sys",
"libc", "libc",
"wasi 0.11.0+wasi-snapshot-preview1", "wasi 0.11.0+wasi-snapshot-preview1",
@ -1822,7 +1790,7 @@ dependencies = [
"core-foundation-sys", "core-foundation-sys",
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -1875,9 +1843,9 @@ dependencies = [
[[package]] [[package]]
name = "inotify" name = "inotify"
version = "0.7.1" version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"inotify-sys", "inotify-sys",
@ -1899,7 +1867,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
] ]
[[package]] [[package]]
@ -1918,15 +1886,6 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06" checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06"
[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.5.0" version = "2.5.0"
@ -1940,7 +1899,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04a4202a60e86f1c9702706bb42270dadd333f2db7810157563c86f17af3c873" checksum = "04a4202a60e86f1c9702706bb42270dadd333f2db7810157563c86f17af3c873"
dependencies = [ dependencies = [
"users 0.10.0", "users 0.10.0",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -1961,7 +1920,7 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa9acdc6d67b75e626ad644734e8bc6df893d9cd2a834129065d3dd6158ea9c8" checksum = "fa9acdc6d67b75e626ad644734e8bc6df893d9cd2a834129065d3dd6158ea9c8"
dependencies = [ dependencies = [
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -2029,13 +1988,23 @@ dependencies = [
] ]
[[package]] [[package]]
name = "kernel32-sys" name = "kqueue"
version = "0.2.2" version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" checksum = "2c8fc60ba15bf51257aa9807a48a61013db043fcf3a78cb0d916e8e396dcad98"
dependencies = [ dependencies = [
"winapi 0.2.8", "kqueue-sys",
"winapi-build", "libc",
]
[[package]]
name = "kqueue-sys"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587"
dependencies = [
"bitflags",
"libc",
] ]
[[package]] [[package]]
@ -2149,8 +2118,8 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -2238,7 +2207,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
] ]
[[package]] [[package]]
@ -2417,25 +2386,6 @@ dependencies = [
"adler", "adler",
] ]
[[package]]
name = "mio"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4"
dependencies = [
"cfg-if 0.1.10",
"fuchsia-zircon",
"fuchsia-zircon-sys",
"iovec",
"kernel32-sys",
"libc",
"log",
"miow",
"net2",
"slab",
"winapi 0.2.8",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.8.4" version = "0.8.4"
@ -2448,30 +2398,6 @@ dependencies = [
"windows-sys 0.36.1", "windows-sys 0.36.1",
] ]
[[package]]
name = "mio-extras"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
dependencies = [
"lazycell",
"log",
"mio 0.6.23",
"slab",
]
[[package]]
name = "miow"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d"
dependencies = [
"kernel32-sys",
"net2",
"winapi 0.2.8",
"ws2_32-sys",
]
[[package]] [[package]]
name = "multiversion" name = "multiversion"
version = "0.6.1" version = "0.6.1"
@ -2525,17 +2451,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae"
[[package]]
name = "net2"
version = "0.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae"
dependencies = [
"cfg-if 0.1.10",
"libc",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "new_debug_unreachable" name = "new_debug_unreachable"
version = "1.0.4" version = "1.0.4"
@ -2550,7 +2465,7 @@ checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bitflags", "bitflags",
"cfg-if 1.0.0", "cfg-if",
"libc", "libc",
] ]
@ -2594,20 +2509,20 @@ dependencies = [
[[package]] [[package]]
name = "notify" name = "notify"
version = "4.0.17" version = "5.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" checksum = "58ea850aa68a06e48fdb069c0ec44d0d64c8dbffa49bf3b6f7f0a901fdea1ba9"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"crossbeam-channel",
"filetime", "filetime",
"fsevent",
"fsevent-sys", "fsevent-sys",
"inotify", "inotify",
"kqueue",
"libc", "libc",
"mio 0.6.23", "mio",
"mio-extras",
"walkdir", "walkdir",
"winapi 0.3.9", "windows-sys 0.42.0",
] ]
[[package]] [[package]]
@ -2625,7 +2540,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc" checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc"
dependencies = [ dependencies = [
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -2680,7 +2595,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [ dependencies = [
"overload", "overload",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -2964,7 +2879,7 @@ dependencies = [
"ntapi", "ntapi",
"once_cell", "once_cell",
"procfs", "procfs",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -3283,7 +3198,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if 1.0.0", "cfg-if",
"foreign-types", "foreign-types",
"libc", "libc",
"once_cell", "once_cell",
@ -3353,7 +3268,7 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
dependencies = [ dependencies = [
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -3408,12 +3323,12 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"instant", "instant",
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec", "smallvec",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -3422,7 +3337,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec", "smallvec",
@ -4296,7 +4211,7 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [ dependencies = [
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -4404,7 +4319,7 @@ version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7229b505ae0706e64f37ffc54a9c163e11022a6636d58fe1f3f52018257ff9f7" checksum = "7229b505ae0706e64f37ffc54a9c163e11022a6636d58fe1f3f52018257ff9f7"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"proc-macro2", "proc-macro2",
"quote", "quote",
"rustc_version 0.4.0", "rustc_version 0.4.0",
@ -4466,7 +4381,7 @@ version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"ordered-multimap", "ordered-multimap",
] ]
@ -4758,7 +4673,7 @@ version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"cpufeatures", "cpufeatures",
"digest", "digest",
] ]
@ -4803,7 +4718,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
dependencies = [ dependencies = [
"libc", "libc",
"mio 0.8.4", "mio",
"signal-hook", "signal-hook",
] ]
@ -4898,7 +4813,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
dependencies = [ dependencies = [
"libc", "libc",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -5079,7 +4994,7 @@ dependencies = [
"libc", "libc",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -5088,12 +5003,12 @@ version = "0.27.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "975fe381e0ecba475d4acff52466906d95b153a40324956552e027b2a9eaa89e" checksum = "975fe381e0ecba475d4acff52466906d95b153a40324956552e027b2a9eaa89e"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
"ntapi", "ntapi",
"once_cell", "once_cell",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -5102,13 +5017,13 @@ version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "727220a596b4ca0af040a07091e49f5c105ec8f2592674339a5bf35be592f76e" checksum = "727220a596b4ca0af040a07091e49f5c105ec8f2592674339a5bf35be592f76e"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
"ntapi", "ntapi",
"once_cell", "once_cell",
"rayon", "rayon",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -5142,12 +5057,12 @@ version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"fastrand", "fastrand",
"libc", "libc",
"redox_syscall", "redox_syscall",
"remove_dir_all", "remove_dir_all",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -5177,7 +5092,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [ dependencies = [
"libc", "libc",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -5256,7 +5171,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [ dependencies = [
"libc", "libc",
"wasi 0.10.0+wasi-snapshot-preview1", "wasi 0.10.0+wasi-snapshot-preview1",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -5332,7 +5247,7 @@ dependencies = [
"bytes", "bytes",
"libc", "libc",
"memchr", "memchr",
"mio 0.8.4", "mio",
"num_cpus", "num_cpus",
"pin-project-lite", "pin-project-lite",
"socket2", "socket2",
@ -5418,7 +5333,7 @@ version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"pin-project-lite", "pin-project-lite",
"tracing-core", "tracing-core",
] ]
@ -5719,7 +5634,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [ dependencies = [
"same-file", "same-file",
"winapi 0.3.9", "winapi",
"winapi-util", "winapi-util",
] ]
@ -5757,7 +5672,7 @@ version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"wasm-bindgen-macro", "wasm-bindgen-macro",
] ]
@ -5782,7 +5697,7 @@ version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
@ -5871,12 +5786,6 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"
@ -5887,12 +5796,6 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu",
] ]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
[[package]] [[package]]
name = "winapi-i686-pc-windows-gnu" name = "winapi-i686-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
@ -5905,7 +5808,7 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [ dependencies = [
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -6053,7 +5956,7 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [ dependencies = [
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -6062,8 +5965,8 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76a1a57ff50e9b408431e8f97d5456f2807f8eb2a2cd79b06068fc87f8ecf189" checksum = "76a1a57ff50e9b408431e8f97d5456f2807f8eb2a2cd79b06068fc87f8ecf189"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"winapi 0.3.9", "winapi",
] ]
[[package]] [[package]]
@ -6075,16 +5978,6 @@ dependencies = [
"toml 0.5.9", "toml 0.5.9",
] ]
[[package]]
name = "ws2_32-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]] [[package]]
name = "xmlparser" name = "xmlparser"
version = "0.13.5" version = "0.13.5"

View file

@ -61,7 +61,7 @@ lscolors = { version = "0.12.0", features = ["crossterm"], default-features = fa
md5 = { package = "md-5", version = "0.10.0" } md5 = { package = "md-5", version = "0.10.0" }
mime = "0.3.16" mime = "0.3.16"
mime_guess = "2.0.4" mime_guess = "2.0.4"
notify = "4.0.17" notify = "5.1.0"
num = { version = "0.4.0", optional = true } num = { version = "0.4.0", optional = true }
num-traits = "0.2.14" num-traits = "0.2.14"
once_cell = "1.17" once_cell = "1.17"

View file

@ -2,7 +2,7 @@ use std::path::PathBuf;
use std::sync::mpsc::{channel, RecvTimeoutError}; use std::sync::mpsc::{channel, RecvTimeoutError};
use std::time::Duration; use std::time::Duration;
use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher}; use notify::{recommended_watcher, EventKind, RecursiveMode, Watcher};
use nu_engine::{current_dir, eval_block, CallExt}; use nu_engine::{current_dir, eval_block, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Closure, Command, EngineState, Stack, StateWorkingSet}; use nu_protocol::engine::{Closure, Command, EngineState, Stack, StateWorkingSet};
@ -13,7 +13,6 @@ use nu_protocol::{
// durations chosen mostly arbitrarily // durations chosen mostly arbitrarily
const CHECK_CTRL_C_FREQUENCY: Duration = Duration::from_millis(100); const CHECK_CTRL_C_FREQUENCY: Duration = Duration::from_millis(100);
const DEFAULT_WATCH_DEBOUNCE_DURATION: Duration = Duration::from_millis(100);
#[derive(Clone)] #[derive(Clone)]
pub struct Watch; pub struct Watch;
@ -38,12 +37,6 @@ impl Command for Watch {
.required("closure", .required("closure",
SyntaxShape::Closure(Some(vec![SyntaxShape::String, SyntaxShape::String, SyntaxShape::String])), SyntaxShape::Closure(Some(vec![SyntaxShape::String, SyntaxShape::String, SyntaxShape::String])),
"Some Nu code to run whenever a file changes. The closure will be passed `operation`, `path`, and `new_path` (for renames only) arguments in that order") "Some Nu code to run whenever a file changes. The closure will be passed `operation`, `path`, and `new_path` (for renames only) arguments in that order")
.named(
"debounce-ms",
SyntaxShape::Int,
"Debounce changes for this many milliseconds (default: 100). Adjust if you find that single writes are reported as multiple events",
Some('d'),
)
.named( .named(
"glob", "glob",
SyntaxShape::String, // SyntaxShape::GlobPattern gets interpreted relative to cwd, so use String instead SyntaxShape::String, // SyntaxShape::GlobPattern gets interpreted relative to cwd, so use String instead
@ -91,22 +84,6 @@ impl Command for Watch {
.clone(); .clone();
let verbose = call.has_flag("verbose"); let verbose = call.has_flag("verbose");
let debounce_duration_flag: Option<Spanned<i64>> =
call.get_flag(engine_state, stack, "debounce-ms")?;
let debounce_duration = match debounce_duration_flag {
Some(val) => match u64::try_from(val.item) {
Ok(val) => Duration::from_millis(val),
Err(_) => {
return Err(ShellError::TypeMismatch(
"Debounce duration is invalid".to_string(),
val.span,
))
}
},
None => DEFAULT_WATCH_DEBOUNCE_DURATION,
};
let glob_flag: Option<Spanned<String>> = call.get_flag(engine_state, stack, "glob")?; let glob_flag: Option<Spanned<String>> = call.get_flag(engine_state, stack, "glob")?;
let glob_pattern = match glob_flag { let glob_pattern = match glob_flag {
Some(glob) => { Some(glob) => {
@ -144,7 +121,7 @@ impl Command for Watch {
let ctrlc_ref = &engine_state.ctrlc.clone(); let ctrlc_ref = &engine_state.ctrlc.clone();
let (tx, rx) = channel(); let (tx, rx) = channel();
let mut watcher: RecommendedWatcher = match Watcher::new(tx, debounce_duration) { let mut watcher = match recommended_watcher(tx) {
Ok(w) => w, Ok(w) => w,
Err(e) => { Err(e) => {
return Err(ShellError::IOError(format!( return Err(ShellError::IOError(format!(
@ -152,104 +129,83 @@ impl Command for Watch {
))) )))
} }
}; };
if let Err(e) = watcher.watch(&path, recursive_mode) {
if let Err(e) = watcher.watch(path.clone(), recursive_mode) {
return Err(ShellError::IOError(format!("Failed to start watcher: {e}"))); return Err(ShellError::IOError(format!("Failed to start watcher: {e}")));
} }
eprintln!("Now watching files at {path:?}. Press ctrl+c to abort."); eprintln!("Now watching files at {path:?}. Press ctrl+c to abort.");
let event_handler = let event_handler = |operation: &str, path: PathBuf| -> Result<(), ShellError> {
|operation: &str, path: PathBuf, new_path: Option<PathBuf>| -> Result<(), ShellError> { let glob_pattern = glob_pattern.clone();
let glob_pattern = glob_pattern.clone(); let matches_glob = match glob_pattern.clone() {
let matches_glob = match glob_pattern.clone() { Some(glob) => glob.matches_path(&path),
Some(glob) => glob.matches_path(&path), None => true,
None => true,
};
if verbose && glob_pattern.is_some() {
eprintln!("Matches glob: {matches_glob}");
}
if matches_glob {
let stack = &mut stack.clone();
if let Some(position) = block.signature.get_positional(0) {
if let Some(position_id) = &position.var_id {
stack.add_var(*position_id, Value::string(operation, call.span()));
}
}
if let Some(position) = block.signature.get_positional(1) {
if let Some(position_id) = &position.var_id {
stack.add_var(
*position_id,
Value::string(path.to_string_lossy(), call.span()),
);
}
}
if let Some(position) = block.signature.get_positional(2) {
if let Some(position_id) = &position.var_id {
stack.add_var(
*position_id,
Value::string(
new_path.unwrap_or_else(|| "".into()).to_string_lossy(),
call.span(),
),
);
}
}
let eval_result = eval_block(
engine_state,
stack,
&block,
Value::Nothing { span: call.span() }.into_pipeline_data(),
call.redirect_stdout,
call.redirect_stderr,
);
match eval_result {
Ok(val) => {
val.print(engine_state, stack, false, false)?;
}
Err(err) => {
let working_set = StateWorkingSet::new(engine_state);
eprintln!("{}", format_error(&working_set, &err));
}
}
}
Ok(())
}; };
if verbose && glob_pattern.is_some() {
eprintln!("Matches glob: {matches_glob}");
}
if matches_glob {
let stack = &mut stack.clone();
if let Some(position) = block.signature.get_positional(0) {
if let Some(position_id) = &position.var_id {
stack.add_var(*position_id, Value::string(operation, call.span()));
}
}
if let Some(position) = block.signature.get_positional(1) {
if let Some(position_id) = &position.var_id {
stack.add_var(
*position_id,
Value::string(path.to_string_lossy(), call.span()),
);
}
}
let eval_result = eval_block(
engine_state,
stack,
&block,
Value::Nothing { span: call.span() }.into_pipeline_data(),
call.redirect_stdout,
call.redirect_stderr,
);
match eval_result {
Ok(val) => {
val.print(engine_state, stack, false, false)?;
}
Err(err) => {
let working_set = StateWorkingSet::new(engine_state);
eprintln!("{}", format_error(&working_set, &err));
}
}
}
Ok(())
};
loop { loop {
match rx.recv_timeout(CHECK_CTRL_C_FREQUENCY) { match rx.recv_timeout(CHECK_CTRL_C_FREQUENCY) {
Ok(event) => { Ok(Ok(mut event)) => {
if verbose { if verbose {
eprintln!("{event:?}"); eprintln!("{event:?}");
} }
let handler_result = match event { let path = match event.paths.pop() {
DebouncedEvent::Create(path) => event_handler("Create", path, None), None => continue,
DebouncedEvent::Write(path) => event_handler("Write", path, None), Some(p) => p,
DebouncedEvent::Remove(path) => event_handler("Remove", path, None),
DebouncedEvent::Rename(path, new_path) => {
event_handler("Rename", path, Some(new_path))
}
DebouncedEvent::Error(err, path) => match path {
Some(path) => Err(ShellError::IOError(format!(
"Error detected for {path:?}: {err:?}"
))),
None => Err(ShellError::IOError(format!("Error detected: {err:?}"))),
},
// These are less likely to be interesting events
DebouncedEvent::Chmod(_)
| DebouncedEvent::NoticeRemove(_)
| DebouncedEvent::NoticeWrite(_)
| DebouncedEvent::Rescan => Ok(()),
}; };
handler_result?; match event.kind {
EventKind::Create(_) => event_handler("Create", path),
EventKind::Modify(notify::event::ModifyKind::Data(_)) => {
event_handler("Write", path)
}
EventKind::Remove(_) => event_handler("Remove", path),
_ => Ok(()),
}?
} }
Ok(Err(e)) => return Err(ShellError::IOError(format!("watch error: {e}"))),
Err(RecvTimeoutError::Disconnected) => { Err(RecvTimeoutError::Disconnected) => {
return Err(ShellError::IOError( return Err(ShellError::IOError(
"Unexpected disconnect from file watcher".into(), "Unexpected disconnect from file watcher".into(),
@ -274,7 +230,7 @@ impl Command for Watch {
}, },
Example { Example {
description: "Watch all changes in the current directory", description: "Watch all changes in the current directory",
example: r#"watch . { |op, path, new_path| $"($op) ($path) ($new_path)"}"#, example: r#"watch . { |op, path| $"($op) ($path)"}"#,
result: None, result: None,
}, },
Example { Example {