Skip to content

Watching a directory fails when it encounters a symbolic link to a nonexistent file #727

@EugeneOne1

Description

@EugeneOne1

Describe the bug

fsnotify.Watcher.Add with a directory instead of file (at least in kqueue implementation) ignores all files after the first symbolic link that points to a nonexistent file and returns a file does not exist error.

This change is suspected.

Code to Reproduce

Code

package main

import (
	"github.com/fsnotify/fsnotify"
)

func check(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	w, err := fsnotify.NewWatcher()
	check(err)
	defer w.Close()

	err = w.Add("/another/directory")
	check(err)
}

Expected result

Exit code: 0

Actual result

panic: "/another/directory/aaa": no such file or directory

File operations to reproduce

Note

These steps should be made before running the code.

  1. $ touch /some/directory/aaa
  2. $ ln -s /another/directory/aaa /some/directory/aaa
  3. $ rm /some/directory/aaa

Which operating system and version are you using?

ProductName:            macOS
ProductVersion:         26.1
BuildVersion:           25B78

Which fsnotify version are you using?

1.9.0

Did you try the latest main branch?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions