From 5b7e20e5f470e2ec522ad6f582d1a21f676afd3f Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Sat, 24 May 2025 20:39:35 -0400 Subject: [PATCH] Fix rename debouncer to preserve paths --- libmarlin/src/watcher.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libmarlin/src/watcher.rs b/libmarlin/src/watcher.rs index 8d21aad..cfcb2ca 100644 --- a/libmarlin/src/watcher.rs +++ b/libmarlin/src/watcher.rs @@ -158,16 +158,25 @@ impl EventDebouncer { .retain(|p, _| !p.starts_with(&path) || p == &path); } - match self.events.get_mut(&path) { - Some(existing) => { + use std::collections::hash_map::Entry; + + match self.events.entry(path) { + Entry::Occupied(mut o) => { + let existing = o.get_mut(); if event.priority < existing.priority { existing.priority = event.priority; } existing.kind = event.kind; existing.timestamp = event.timestamp; + if let Some(old_p) = event.old_path { + existing.old_path = Some(old_p); + } + if let Some(new_p) = event.new_path { + existing.new_path = Some(new_p); + } } - None => { - self.events.insert(path, event); + Entry::Vacant(v) => { + v.insert(event); } } }