Skip to content

Directory moved from one watched directory to another is not recursively watched #491

@emilycf-cw

Description

@emilycf-cw

System details

  • OS: Linux pop-os 6.2.6-76060206-generic
  • Rust version: rustc 1.70.0 (90c541806 2023-05-31)
  • Notify version: 6.0.0
  • Filesystem type and options: ext4
  • Linux kernel version: 6.2.6-76060206-generic
  • If you're running as a privileged user (root, System): no

What you did (as detailed as you can)

Code

use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};

/// Async, futures channel based event watching
fn main() {
    let mut args = std::env::args();
    let _ = args.next();
    let path_1 = args.next()
        .expect("Argument 1 needs to be a path");
    let path_2 = args.next();

    let (tx, rx) = std::sync::mpsc::channel();

    // Automatically select the best implementation for your platform.
    // You can also access each implementation directly e.g. INotifyWatcher.
    let mut main_watcher = RecommendedWatcher::new(
        move |res| {
            tx.send(res).expect("channel closed");
        },
        Config::default(),
    ).expect("Failed to create watcher");
    // Add a path to be watched. All files and directories at that path and
    // below will be monitored for changes.
    println!("watching {path_1} recursively");
    main_watcher.watch(path_1.as_ref(), RecursiveMode::Recursive).expect("Failed to watch first path");
    if let Some(path_2) = path_2 {
        println!("watching {path_2} recursively");
        main_watcher.watch(path_2.as_ref(), RecursiveMode::Recursive).expect("Failed to watch second path");
    }

    while let Ok(res) = rx.recv() {
        match res {
            Ok(event) => println!("{:?}: {:?}", event.kind, event.paths),
            Err(e) => println!("watch error: {:?}", e),
        }
    }
}

In one terminal: cargo run -- dir-1 dir-2

In another terminal:

$ mkdir dir-2/subdir
$ mv dir-2/subdir dir-1
$ touch dir-1/subdir/file

What you expected

After moving a directory from one watched directory to another recursively watched directory, the moved directory is watched.

Expected output (produced by running the same code, but using notify v5.1.0 instead of v6.0.0:

watching dir-1 recursively
watching dir-2 recursively
Create(Folder): ["/home/emilycf/rust/notify-playground/dir-2/subdir"]
Modify(Name(From)): ["/home/emilycf/rust/notify-playground/dir-2/subdir"]
Modify(Name(To)): ["/home/emilycf/rust/notify-playground/dir-1/subdir"]
Modify(Name(Both)): ["/home/emilycf/rust/notify-playground/dir-2/subdir", "/home/emilycf/rust/notify-playground/dir-1/subdir"]
Create(File): ["/home/emilycf/rust/notify-playground/dir-1/subdir/file"]
Modify(Metadata(Any)): ["/home/emilycf/rust/notify-playground/dir-1/subdir/file"]
Access(Close(Write)): ["/home/emilycf/rust/notify-playground/dir-1/subdir/file"]

What happened

After the directory was moved, no events were generated.

Actual output:

watching dir-1 recursively
watching dir-2 recursively
Create(Folder): ["/home/emilycf/rust/notify-playground/dir-2/subdir"]
Modify(Name(From)): ["/home/emilycf/rust/notify-playground/dir-2/subdir"]
Modify(Name(To)): ["/home/emilycf/rust/notify-playground/dir-1/subdir"]
Modify(Name(Both)): ["/home/emilycf/rust/notify-playground/dir-2/subdir", "/home/emilycf/rust/notify-playground/dir-1/subdir"]

Notice there is no event for the touch dir-1/subdir/file command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-bugB-unconfirmedNeeds verification (by maintainer or testing party)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions