Fix the issue of notifying parent in fsnotify

This commit is contained in:
Zhenchen Wang 2025-12-24 09:52:15 +00:00 committed by Chengjun Chen
parent 2c80e0c3a4
commit cd7859161d
2 changed files with 14 additions and 2 deletions

View File

@ -419,7 +419,7 @@ fn notify_parent(path: &Path, mut events: FsEvents, name: String) {
events |= FsEvents::ISDIR;
}
let parent = path.effective_parent();
let parent = path.parent_within_mount();
if let Some(parent) = parent {
notify_inode(parent.inode(), events, Some(name));
}

View File

@ -165,7 +165,7 @@ impl Path {
///
/// If it is the root of a mount, it will go up to the mountpoint
/// to get the parent of the mountpoint recursively.
pub fn effective_parent(&self) -> Option<Self> {
fn effective_parent(&self) -> Option<Self> {
if !self.is_mount_root() {
return Some(Self::new(self.mount.clone(), self.dentry.parent().unwrap()));
}
@ -177,6 +177,18 @@ impl Path {
mount_parent.effective_parent()
}
/// Gets the parent `Path` within the same mount.
///
/// This method returns the parent path within the same filesystem/mount.
/// It does NOT cross mount boundaries. If the current path is the root of a mount,
/// it will return `None`.
///
/// For cross-filesystem parent lookup, use `effective_parent()` instead.
pub(super) fn parent_within_mount(&self) -> Option<Self> {
let parent = self.dentry.parent()?;
Some(Self::new(self.mount.clone(), parent))
}
/// Gets the top `Path` of the current.
///
/// Used when different file systems are mounted on the same mount point.