Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

RemoveWatch is not removing the path from the watch list #71

Closed
mdwhatcott opened this issue Oct 16, 2013 · 2 comments
Closed

RemoveWatch is not removing the path from the watch list #71

mdwhatcott opened this issue Oct 16, 2013 · 2 comments

Comments

@mdwhatcott
Copy link

I'm running Go 1.1.2 on Mac OS Lion (x64). I've included some test code below. Am I missing something?

package stuff

import (
    "github.com/howeyc/fsnotify"
    "os"
    "os/exec"
    "testing"
    "time"
)

func TestRemovalOfWatch(t *testing.T) {
    defer exec.Command("rm", "file.txt").Run() // cleanup file system after test

    exec.Command("touch", "file.txt").Run()

    watcher, err := fsnotify.NewWatcher()
    if err != nil {
        panic(err)
    }
    defer watcher.Close()

    working, _ := os.Getwd()
    watcher.Watch(working)
    err = watcher.RemoveWatch(working)
    if err != nil {
        t.Fatalf("Could not remove the watch: %v\n", err)
    }

    go func() {
        for {
            select {
            case ev := <-watcher.Event:
                t.Errorf("We should no longer be watching anything but we received this event:\n%v", ev)
            }
        }
    }()

    time.Sleep(1 * time.Second) // let the RemoveWatch sink in?
    exec.Command("touch", "file.txt").Run()
    time.Sleep(1 * time.Second) // allow time for the event to propogate
}

/* OUTPUT
$ go test
--- FAIL: TestRemovalOfWatch (2.02 seconds)
    stuff_test.go:33: We should no longer be watching anything but we received this event:
        "/Users/mike/work/dev/gopath/src/github.com/mdwhatcott/stuff/file.txt": MODIFY
FAIL
exit status 1
FAIL    github.com/smartystreets/stuff  2.035s

*/

howeyc added a commit that referenced this issue Oct 19, 2013
The issue was that files watched internally were not being removed
when the parent directory's watch was removed.
@howeyc
Copy link
Owner

howeyc commented Oct 19, 2013

What you were doing is correct. I had an issue in the library that files watched for a user directory watch were not being unwatched when the user's directory watch was removed.

Whenever you get a chance please try with the latest changes made and report if this behaves as expected.

@mdwhatcott
Copy link
Author

That worked @howeyc! Thanks for the quick fix.

rsc pushed a commit to golang/exp that referenced this issue Dec 7, 2014
Handle ERROR_MORE_DATA on Windows
(howeyc/fsnotify#49)

Run tests in random temp directories
(howeyc/fsnotify#57)

Fix: RemoveWatch is not removing the path from the watch list
The issue was that files watched internally were not being removed
when the parent directory's watch was removed.
(howeyc/fsnotify#71)

Fix: Race on OS X between Close() and readEvents()
(howeyc/fsnotify#70)

Fix: deadlock on BSD
The removeWatch routine could return without releasing the lock on
w.bufmut. This change unlocks the mutex before checking for errors.
(howeyc/fsnotify#77)

Add an IsAttrib method on the FileEvent struct
(howeyc/fsnotify#79)

Fix: a few typos

Test helpers for shared setup.

LGTM=iant
R=golang-codereviews, dave, alex.brainman, gobot, bradfitz, iant
CC=bradfitz, bronze1man, cespare, denis.brandolini, golang-codereviews, henrik.edwards, jbowtie, travis.cline, webustany
https://golang.org/cl/58500043
GoogleCodeExporter pushed a commit to bsed/go-zh.exp that referenced this issue May 31, 2015
Handle ERROR_MORE_DATA on Windows
(howeyc/fsnotify#49)

Run tests in random temp directories
(howeyc/fsnotify#57)

Fix: RemoveWatch is not removing the path from the watch list
The issue was that files watched internally were not being removed
when the parent directory's watch was removed.
(howeyc/fsnotify#71)

Fix: Race on OS X between Close() and readEvents()
(howeyc/fsnotify#70)

Fix: deadlock on BSD
The removeWatch routine could return without releasing the lock on
w.bufmut. This change unlocks the mutex before checking for errors.
(howeyc/fsnotify#77)

Add an IsAttrib method on the FileEvent struct
(howeyc/fsnotify#79)

Fix: a few typos

Test helpers for shared setup.

LGTM=iant
R=golang-codereviews, dave, alex.brainman, gobot, bradfitz, iant
CC=bradfitz, bronze1man, cespare, denis.brandolini, golang-codereviews, henrik.edwards, jbowtie, travis.cline, webustany
https://codereview.appspot.com/58500043

Committer: Ian Lance Taylor <iant@golang.org>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants