Skip to content

Commit

Permalink
[fuchsia-repo] Rewrite FS notification
Browse files Browse the repository at this point in the history
This patch accounts for a number of complications we've discovered with
the notify library.

First, some notify backends may emit multiple notifications for the same
event. For exampls, FSEvents on OSX will emit at least a create,
modify-metadata, and modify-data events.

Second, the event ordering can be somewhat non-deterministic. This can
happen because the underlying notification system may also batch
multiple events together. For example, on FSEevents,
removing-then-recreating a file can emit a single event that has a
bitfield that has a "delete" and "create" event. The notify library will
unroll this into two separate events, but it doesn't have any way to
tell the ordering of these events.

To help deal with this, this patch creates a "notify-batch-watcher",
which will batch up multiple events that occur over a period of time. We
also drop the precise event kind. If it turns out we need this, we could
add a bitflag field in the future.

Finally, this refactors `PackageManifestWatcher` to use the helper
library, and to simplify the tests to be quite a bit simpler.

Note that this also removes the code accounting for
notify-rs/notify#337, which was fixed in
notify-5.0.0.

Fixed: 117968

Change-Id: I3ac82308f38cb65e4b3d8bf5a50eacb55515f79b
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/794836
Reviewed-by: Gary Bressler <geb@google.com>
Commit-Queue: Erick Tryzelaar <etryzelaar@google.com>
Reviewed-by: Ben Keller <galbanum@google.com>
Fuchsia-Auto-Submit: Erick Tryzelaar <etryzelaar@google.com>
  • Loading branch information
vdonich authored and Rebase bot committed Feb 8, 2023
1 parent 132d9cc commit 362202c
Show file tree
Hide file tree
Showing 7 changed files with 1,308 additions and 543 deletions.
1 change: 1 addition & 0 deletions src/sys/lib/BUILD.gn
Expand Up @@ -25,6 +25,7 @@ group("tests") {
"library_loader:tests",
"mem_util:tests",
"moniker:moniker-tests",
"notify-batch-watcher:tests",
"payload_streamer:tests",
"routing:fuchsia-routing-tests",
"routing:host-routing-tests",
Expand Down
37 changes: 37 additions & 0 deletions src/sys/lib/notify-batch-watcher/BUILD.gn
@@ -0,0 +1,37 @@
# Copyright 2023 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/rust/rustc_library.gni")

# Only supports host for now.
if (is_host) {
rustc_library("notify-batch-watcher") {
version = "0.1.0"
edition = "2021"
with_unit_tests = true

deps = [ "//third_party/rust_crates:notify" ]

test_deps = [
"//third_party/rust_crates:pretty_assertions",
"//third_party/rust_crates:tempfile",
]

sources = [ "src/lib.rs" ]
}

group("tests") {
testonly = true
deps = [ ":notify-batch-watcher_test" ]
}
} else {
group("notify-batch-watcher") {
deps = [ ":notify-batch-watcher($host_toolchain)" ]
}

group("tests") {
testonly = true
deps = [ ":notify-batch-watcher_test($host_toolchain)" ]
}
}
3 changes: 3 additions & 0 deletions src/sys/lib/notify-batch-watcher/OWNERS
@@ -0,0 +1,3 @@
include /src/sys/pkg/OWNERS

# COMPONENT: Packages

0 comments on commit 362202c

Please sign in to comment.