Refactor the multiple "notify" systems into a single helper

structure.

* Creates FileWatcher, in lqos_utils.
* Removes "notify" dependency from other crates.

FileWatcher is designed to watch a file. If the file doesn't exist,
then an optional callback is called - and the watcher waits,
periodically checking to see if the file has appeared yet. When the
file appears, another optional callback is executed.

Once the file exists, a `notify` system is started (it uses Linux's
`inotify` system internally) for that file. When the file changes,
the process sleeps briefly and then executes an `on_change` callback.
Further messages are then suppressed for a short period to avoid
duplicates.

All uses of notify have been updated to use this system. Errors are
handled cleanly, per ISSUE #209.
This commit is contained in:
Herbert Wolverson
2023-01-31 17:52:35 +00:00
parent 3e4e7ebe64
commit 816ca7e651
9 changed files with 192 additions and 106 deletions

6
src/rust/Cargo.lock generated
View File

@@ -1348,8 +1348,8 @@ dependencies = [
"lazy_static",
"lqos_bus",
"lqos_config",
"lqos_utils",
"nix",
"notify",
"parking_lot 0.12.1",
"rocket",
"rocket_async_compression",
@@ -1379,7 +1379,6 @@ dependencies = [
"lqos_config",
"lqos_sys",
"lqos_utils",
"notify",
"parking_lot 0.12.1",
"rayon",
"serde",
@@ -1412,7 +1411,9 @@ version = "0.1.0"
dependencies = [
"log",
"nix",
"notify",
"serde",
"thiserror",
]
[[package]]
@@ -1430,7 +1431,6 @@ dependencies = [
"lqos_sys",
"lqos_utils",
"nix",
"notify",
"parking_lot 0.12.1",
"rayon",
"serde",