From 9a573ad71bd9ae5946b6fb52e243fb40531d1131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20G=C3=A4bler?= <14858479+florian-g2@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:21:07 +0100 Subject: [PATCH 1/2] Allow flexible handle instead of direct borrow for file ids in the FileIdCache --- file-id/src/lib.rs | 6 ++++++ notify-debouncer-full/src/cache.rs | 9 ++++----- notify-debouncer-full/src/lib.rs | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/file-id/src/lib.rs b/file-id/src/lib.rs index 3c0091fd..cd92136f 100644 --- a/file-id/src/lib.rs +++ b/file-id/src/lib.rs @@ -106,6 +106,12 @@ impl FileId { } } +impl AsRef for FileId { + fn as_ref(&self) -> &FileId { + self + } +} + /// Get the `FileId` for the file or directory at `path` #[cfg(target_family = "unix")] pub fn get_file_id(path: impl AsRef) -> io::Result { diff --git a/notify-debouncer-full/src/cache.rs b/notify-debouncer-full/src/cache.rs index a5a5d44e..b0d0b989 100644 --- a/notify-debouncer-full/src/cache.rs +++ b/notify-debouncer-full/src/cache.rs @@ -2,7 +2,6 @@ use std::{ collections::HashMap, path::{Path, PathBuf}, }; - use file_id::{get_file_id, FileId}; use notify::RecursiveMode; use walkdir::WalkDir; @@ -14,7 +13,7 @@ pub trait FileIdCache { /// Get a `FileId` from the cache for a given `path`. /// /// If the path is not cached, `None` should be returned and there should not be any attempt to read the file ID from disk. - fn cached_file_id(&self, path: &Path) -> Option<&FileId>; + fn cached_file_id(&self, path: &Path) -> Option>; /// Add a new path to the cache or update its value. /// @@ -64,7 +63,7 @@ impl FileIdMap { } impl FileIdCache for FileIdMap { - fn cached_file_id(&self, path: &Path) -> Option<&FileId> { + fn cached_file_id(&self, path: &Path) -> Option> { self.paths.get(path) } @@ -104,8 +103,8 @@ impl NoCache { } impl FileIdCache for NoCache { - fn cached_file_id(&self, _path: &Path) -> Option<&FileId> { - None + fn cached_file_id(&self, _path: &Path) -> Option> { + Option::<&FileId>::None } fn add_path(&mut self, _path: &Path, _recursive_mode: RecursiveMode) {} diff --git a/notify-debouncer-full/src/lib.rs b/notify-debouncer-full/src/lib.rs index 2f5528b3..b45c640f 100644 --- a/notify-debouncer-full/src/lib.rs +++ b/notify-debouncer-full/src/lib.rs @@ -340,7 +340,7 @@ impl DebounceDataInner { let path = &event.paths[0]; // store event - let file_id = self.cache.cached_file_id(path).cloned(); + let file_id = self.cache.cached_file_id(path).map(|id| *id.as_ref()); self.rename_event = Some((DebouncedEvent::new(event.clone(), time), file_id)); self.cache.remove_path(path); @@ -372,7 +372,7 @@ impl DebounceDataInner { .and_then(|from_file_id| { self.cache .cached_file_id(&event.paths[0]) - .map(|to_file_id| from_file_id == to_file_id) + .map(|to_file_id| from_file_id == to_file_id.as_ref()) }) .unwrap_or_default(); From 2f4815576e47bf34028121c72c320f29964d32d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20G=C3=A4bler?= <14858479+florian-g2@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:38:59 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97a0fa5e..46daf083 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## debouncer-full 0.6.0 (unreleased) +- FEATURE: allow `FileIdCache` trait implementations to choose ownership of the returned file-ids + +## file-id 0.2.3 (unreleased) +- CHANGE: implement `AsRef` for `FileId` + ## notify 8.0.0 (2025-01-10) - CHANGE: update notify-types to version 2.0.0