From ac5cad1755ae1efc5875d730989597eb9c33e4dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Sep 2022 18:21:59 +0000 Subject: [PATCH 1/2] Bump notify from 4.0.17 to 5.0.0 Bumps [notify](https://github.com/notify-rs/notify) from 4.0.17 to 5.0.0. - [Release notes](https://github.com/notify-rs/notify/releases) - [Changelog](https://github.com/notify-rs/notify/blob/main/CHANGELOG.md) - [Commits](https://github.com/notify-rs/notify/compare/4.0.17...notify-5.0.0) --- updated-dependencies: - dependency-name: notify dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Cargo.lock | 215 ++++++++++++++--------------------------------------- Cargo.toml | 2 +- 2 files changed, 57 insertions(+), 160 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf5b9d3..e4a829e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,7 +121,7 @@ dependencies = [ "actix-utils", "futures-core", "futures-util", - "mio 0.8.4", + "mio", "num_cpus", "socket2", "tokio", @@ -167,7 +167,7 @@ dependencies = [ "ahash", "bytes", "bytestring", - "cfg-if 1.0.0", + "cfg-if", "derive_more", "encoding_rs", "futures-core", @@ -242,7 +242,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -335,7 +335,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -508,12 +508,6 @@ dependencies = [ "jobserver", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -603,13 +597,23 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", ] @@ -686,7 +690,7 @@ version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -708,7 +712,7 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall", "windows-sys", @@ -811,41 +815,15 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fsevent" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" -dependencies = [ - "bitflags", - "fsevent-sys", -] - [[package]] name = "fsevent-sys" -version = "2.0.1" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" dependencies = [ "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]] name = "futures" version = "0.3.24" @@ -945,7 +923,7 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi", ] @@ -1100,9 +1078,9 @@ dependencies = [ [[package]] name = "inotify" -version = "0.7.1" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" dependencies = [ "bitflags", "inotify-sys", @@ -1147,15 +1125,6 @@ dependencies = [ "unic-langid", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "itoa" version = "0.4.8" @@ -1198,13 +1167,23 @@ dependencies = [ ] [[package]] -name = "kernel32-sys" -version = "0.2.2" +name = "kqueue" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +checksum = "4d6112e8f37b59803ac47a42d14f1f3a59bbf72fc6857ffc5be455e28a691f8e" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "kqueue-sys", + "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]] @@ -1219,12 +1198,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" version = "0.2.134" @@ -1295,7 +1268,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1326,25 +1299,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[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]] name = "mio" version = "0.8.4" @@ -1357,41 +1311,6 @@ dependencies = [ "windows-sys", ] -[[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]] -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]] name = "nom" version = "7.1.1" @@ -1404,20 +1323,20 @@ dependencies = [ [[package]] name = "notify" -version = "4.0.17" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" +checksum = "ed2c66da08abae1c024c01d635253e402341b4060a12e99b31c7594063bf490a" dependencies = [ "bitflags", + "crossbeam-channel", "filetime", - "fsevent", "fsevent-sys", "inotify", + "kqueue", "libc", - "mio 0.6.23", - "mio-extras", + "mio", "walkdir", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1486,7 +1405,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall", "smallvec", @@ -1753,7 +1672,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "ordered-multimap", ] @@ -1857,7 +1776,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest", ] @@ -1868,7 +1787,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest", ] @@ -1879,7 +1798,7 @@ version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf9db03534dff993187064c4e0c05a5708d2a9728ace9a8959b77bedf415dac5" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest", ] @@ -1943,7 +1862,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2111,13 +2030,13 @@ dependencies = [ "bytes", "libc", "memchr", - "mio 0.8.4", + "mio", "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2149,7 +2068,7 @@ version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "log", "pin-project-lite", "tracing-core", @@ -2295,7 +2214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -2311,7 +2230,7 @@ version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] @@ -2359,12 +2278,6 @@ version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -2375,12 +2288,6 @@ dependencies = [ "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]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -2393,7 +2300,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2445,16 +2352,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" -[[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]] name = "xmlparser" version = "0.13.3" diff --git a/Cargo.toml b/Cargo.toml index e228160..cbb2404 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ log = "0.4.17" mime = "0.3.16" mime_guess = { version = "2.0.4", default-features = false } nom = { version = "7.1.1", default-features = false, features = [ "alloc" ] } -notify = "4.0.17" +notify = "5.0.0" once_cell = { version = "1.15.0", default-features = false } phf = "0.11.1" regex = { version = "1.6.0", default-features = false } From 05d6bb7c9c00e50a3d1385f0101497391a38cd43 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 2 Sep 2022 18:06:01 +0200 Subject: [PATCH 2/2] Migrate from notify v4 to v5 See https://github.com/notify-rs/notify/blob/main/UPGRADING_V4_TO_V5.md --- Cargo.lock | 11 +++++++ Cargo.toml | 1 + src/package/watcher.rs | 75 +++++++++++++++++++----------------------- 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4a829e..73105de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1339,6 +1339,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "notify-debouncer-mini" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c538ea1dd436b41e751922510cfbcaea2def87ed6ed94aa1edc15dc31b4c179" +dependencies = [ + "crossbeam-channel", + "notify", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -1986,6 +1996,7 @@ dependencies = [ "mime_guess", "nom", "notify", + "notify-debouncer-mini", "once_cell", "phf", "phf_codegen", diff --git a/Cargo.toml b/Cargo.toml index cbb2404..4394f2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ mime = "0.3.16" mime_guess = { version = "2.0.4", default-features = false } nom = { version = "7.1.1", default-features = false, features = [ "alloc" ] } notify = "5.0.0" +notify-debouncer-mini = "0.2.0" once_cell = { version = "1.15.0", default-features = false } phf = "0.11.1" regex = { version = "1.6.0", default-features = false } diff --git a/src/package/watcher.rs b/src/package/watcher.rs index ae1a12f..5e618ba 100644 --- a/src/package/watcher.rs +++ b/src/package/watcher.rs @@ -17,7 +17,9 @@ // SPDX-License-Identifier: AGPL-3.0-or-later use crate::{AUTH_DATA, PACKAGE_LIST, SETTINGS}; -use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher}; +use notify::{RecommendedWatcher, RecursiveMode}; +use notify_debouncer_mini::{new_debouncer, DebounceEventResult, DebouncedEvent, Debouncer}; + use std::{ ffi::OsStr, path::Path, @@ -28,16 +30,18 @@ use std::{ }; pub struct PackageWatcher<'a> { - inner: RecommendedWatcher, + // We need to keep the reference around, to prevent it from being dropped + #[allow(dead_code)] + inner: Debouncer, + path: &'a Path, scanning: Arc>, } impl<'a> PackageWatcher<'a> { - pub fn new(path: &'a Path, tx: Sender) -> notify::Result { - let mut inner = notify::watcher(tx, std::time::Duration::from_secs(5))?; - - inner.watch(&path, RecursiveMode::Recursive)?; + pub fn new(path: &'a Path, tx: Sender) -> notify::Result { + let mut inner = new_debouncer(std::time::Duration::from_secs(5), None, tx)?; + inner.watcher().watch(path, RecursiveMode::Recursive)?; let watcher = Self { inner, @@ -88,45 +92,38 @@ impl<'a> PackageWatcher<'a> { } fn handle_event(&self, event: DebouncedEvent) { - match event { - DebouncedEvent::NoticeWrite(ref path) - | DebouncedEvent::NoticeRemove(ref path) - | DebouncedEvent::Create(ref path) - | DebouncedEvent::Write(ref path) - | DebouncedEvent::Chmod(ref path) - | DebouncedEvent::Remove(ref path) - | DebouncedEvent::Rename(ref path, _) => { - if path.extension() == Some(OsStr::new("tar")) - || path == &self.path.join("auth.json") - { - log::trace!("Re-scan triggered by event: {:#?}", event); - self.start_scan(); - } - } - DebouncedEvent::Rescan => { - log::trace!("Re-scan triggered by DebouncedEvent::Rescan"); - self.start_scan(); - } - DebouncedEvent::Error(..) => { - unreachable!("Error events have been handled in `start_thread` already"); - } + // TODO: Previously we also scanned when we got a "Rescan" event. + // We might have to scan when we get an event where `event.path == self.path`. + + if event.path.extension() == Some(OsStr::new("tar")) + || event.path == self.path.join("auth.json") + { + log::trace!("Re-scan triggered by event: {:#?}", event); + self.start_scan(); } } - pub fn start_watcher(&mut self, rx: Receiver) { + pub fn start_watcher(&mut self, rx: Receiver) { loop { match rx.recv() { - Ok(DebouncedEvent::Error(err, Some(path))) => { - log::error!("Watch error in path {:?}: {:?}", path, err); - } - Ok(DebouncedEvent::Error(err, None)) => { - log::error!("Watch error: {:?}", err); - } Err(err) => { log::error!("Generic watch error, stopping loop: {:?}", err); break; } - Ok(event) => self.handle_event(event), + Ok(Ok(events)) => { + for event in events { + self.handle_event(event) + } + } + Ok(Err(errors)) => { + log::error!( + "Encountered {} errors while processing events:", + errors.len() + ); + for (i, err) in errors.iter().enumerate() { + log::error!("Error #{i}: {err}"); + } + } } } } @@ -139,9 +136,3 @@ impl std::fmt::Debug for PackageWatcher<'_> { .finish() } } - -impl Drop for PackageWatcher<'_> { - fn drop(&mut self) { - self.inner.unwatch(&self.path).unwrap(); - } -}