Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When removing symlink no events happens on MacOS. #636

Open
mbobrovskyi opened this issue May 16, 2024 · 1 comment
Open

When removing symlink no events happens on MacOS. #636

mbobrovskyi opened this issue May 16, 2024 · 1 comment

Comments

@mbobrovskyi
Copy link

mbobrovskyi commented May 16, 2024

Describe the bug

When removing symlink no events happens on MacOS. Also on linux it's working fine.

Code to Reproduce

package main

import (
	"log"

	"github.com/fsnotify/fsnotify"
)

func main() {
	// Create new watcher.
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()

	// Start listening for events.
	go func() {
		for {
			select {
			case event, ok := <-watcher.Events:
				if !ok {
					return
				}
				log.Println("event:", event)
				if event.Has(fsnotify.Write) {
					log.Println("modified file:", event.Name)
				}
			case err, ok := <-watcher.Errors:
				if !ok {
					return
				}
				log.Println("error:", err)
			}
		}
	}()

	// Add a path.
	err = watcher.Add("./tmp")
	if err != nil {
		log.Fatal(err)
	}

	// Block main goroutine forever.
	<-make(chan struct{})
}

File operations to reproduce

touch tmp/test.txt
# event: CREATE        "tmp/test.txt"

ln -s tmp/test.txt tmp/link.txt
# event: CREATE        "tmp/link.txt" 

rm tmp/link.txt
# 

Which operating system and version are you using?

ProductName: macOS
ProductVersion: 14.4.1
BuildVersion: 23E224

Which fsnotify version are you using?

v1.7.0

Did you try the latest main branch?

Yes

@arp242
Copy link
Member

arp242 commented May 16, 2024

Yeah, it's been like this for ages, or at least for as long as I've been involved: https://github.com/fsnotify/fsnotify/blob/main/testdata/watch-dir/remove-symlink#L13

Doesn't seem to be an easy fix; I'll probably pick this up when I rewrite the kqueue backend to support recursion and some other features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants