Skip to content

Commit

Permalink
Merge pull request #437 from p4l1ly/master
Browse files Browse the repository at this point in the history
Filter out non-mutating open events
  • Loading branch information
Yeicor authored Dec 7, 2024
2 parents a008e2c + b1c96bf commit 04fd27e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
22 changes: 16 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ app = ["standalone", "sdf", "sdfdemo", "wasminterpreters", # <-- other features

# The simple server to watch and serve files to the app.
server = ["standalone", # <-- other features
"salvo", "notify-debouncer-mini", "anyhow", "httpdate", "lru", "tokio/process"]
"salvo", "notify-debouncer-full", "anyhow", "httpdate", "lru", "tokio/process"]

# Convert the SDF to a 3D model. Adds a command and a toolbar option (if app) for generating triangle meshes
meshers = ["standalone", "sdf", "wasminterpreters", # <-- other features
Expand Down Expand Up @@ -74,7 +74,7 @@ ehttp = { version = "0.5", optional = true } # Very simple HTTP client that supp

# === SERVER ===
salvo = { version = "0.74", optional = true } # Simple HTTP server
notify-debouncer-mini = { version = "*", default-features = false, optional = true } # Watch for file changes
notify-debouncer-full = { version = "*", default-features = false, optional = true } # Watch for file changes
httpdate = { version = "1.0", optional = true } # Formatting of dates
lru = { version = "0.12", optional = true } # For caching resources

Expand Down
15 changes: 9 additions & 6 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::time::SystemTime;

use httpdate::fmt_http_date;
use lru::LruCache;
use notify_debouncer_mini::notify::RecursiveMode;
use notify_debouncer_mini::{new_debouncer, DebounceEventResult};
use notify_debouncer_full::notify::{event::AccessKind, EventKind, RecursiveMode};
use notify_debouncer_full::{new_debouncer, DebounceEventResult};
use salvo::conn::Acceptor;
use salvo::http::header::HeaderName;
use salvo::http::response::ResBody;
Expand Down Expand Up @@ -274,10 +274,10 @@ impl CliServer {

// Select recommended watcher for debouncer.
// Using a callback here, could also be a channel.
let mut debouncer = new_debouncer(self.watch_merge_ns, move |res: DebounceEventResult| {
let mut debouncer = new_debouncer(self.watch_merge_ns, None, move |res: DebounceEventResult| {
match res {
Ok(events) => {
events.iter().for_each(|e| println!("Event {:?} for {:?}", e.kind, e.path));
events.iter().for_each(|e| println!("Event {:?} for {:?}", e.kind, e.paths));
if !events.is_empty() {
tx.send(events).unwrap();
}
Expand All @@ -289,12 +289,15 @@ impl CliServer {
// Watch all files in the watch_paths (recursively if they are directories).
for path in &watch_paths {
tracing::info!(path=path, "Recursively watching path for changes");
debouncer.watcher().watch(Path::new(path), RecursiveMode::Recursive)?;
debouncer.watch(Path::new(path), RecursiveMode::Recursive)?;
}

let mut cur_event = 1u64;
for x in rx {
// TODO: Event kind filtering
if x.iter().all(|event|
matches!(event.kind, EventKind::Access(AccessKind::Open(_)))) {
continue;
}
let notified = modified_sender_clone.send(cur_event)? - 1 /* initial receiver always available */;
tracing::info!(cur_event=cur_event, "Notifying of file update ({:?}) to {} receivers", x, notified);
cur_event += 1;
Expand Down

0 comments on commit 04fd27e

Please sign in to comment.