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

Document and test removing watched directory on Windows #589

Merged
merged 1 commit into from Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend_fen.go
Expand Up @@ -72,6 +72,11 @@ import (
// Paths can be added as "C:\path\to\dir", but forward slashes
// ("C:/path/to/dir") will also work.
//
// When a watched directory is removed it will always send an event for the
// directory itself, but may not send events for all files in that directory.
// Sometimes it will send events for all times, sometimes it will send no
// events, and often only for some files.
//
// The default buffer size is 64K, which is the largest value that is guaranteed
// to work with SMB filesystems. If you have many events in quick succession
// this may not be enough, and you will have to use [WithBufferSize] to increase
Expand Down
5 changes: 5 additions & 0 deletions backend_inotify.go
Expand Up @@ -75,6 +75,11 @@ import (
// Paths can be added as "C:\path\to\dir", but forward slashes
// ("C:/path/to/dir") will also work.
//
// When a watched directory is removed it will always send an event for the
// directory itself, but may not send events for all files in that directory.
// Sometimes it will send events for all times, sometimes it will send no
// events, and often only for some files.
//
// The default buffer size is 64K, which is the largest value that is guaranteed
// to work with SMB filesystems. If you have many events in quick succession
// this may not be enough, and you will have to use [WithBufferSize] to increase
Expand Down
5 changes: 5 additions & 0 deletions backend_kqueue.go
Expand Up @@ -72,6 +72,11 @@ import (
// Paths can be added as "C:\path\to\dir", but forward slashes
// ("C:/path/to/dir") will also work.
//
// When a watched directory is removed it will always send an event for the
// directory itself, but may not send events for all files in that directory.
// Sometimes it will send events for all times, sometimes it will send no
// events, and often only for some files.
//
// The default buffer size is 64K, which is the largest value that is guaranteed
// to work with SMB filesystems. If you have many events in quick succession
// this may not be enough, and you will have to use [WithBufferSize] to increase
Expand Down
5 changes: 5 additions & 0 deletions backend_other.go
Expand Up @@ -64,6 +64,11 @@ import "errors"
// Paths can be added as "C:\path\to\dir", but forward slashes
// ("C:/path/to/dir") will also work.
//
// When a watched directory is removed it will always send an event for the
// directory itself, but may not send events for all files in that directory.
// Sometimes it will send events for all times, sometimes it will send no
// events, and often only for some files.
//
// The default buffer size is 64K, which is the largest value that is guaranteed
// to work with SMB filesystems. If you have many events in quick succession
// this may not be enough, and you will have to use [WithBufferSize] to increase
Expand Down
5 changes: 5 additions & 0 deletions backend_windows.go
Expand Up @@ -80,6 +80,11 @@ import (
// Paths can be added as "C:\path\to\dir", but forward slashes
// ("C:/path/to/dir") will also work.
//
// When a watched directory is removed it will always send an event for the
// directory itself, but may not send events for all files in that directory.
// Sometimes it will send events for all times, sometimes it will send no
// events, and often only for some files.
//
// The default buffer size is 64K, which is the largest value that is guaranteed
// to work with SMB filesystems. If you have many events in quick succession
// this may not be enough, and you will have to use [WithBufferSize] to increase
Expand Down
120 changes: 60 additions & 60 deletions fsnotify_test.go
Expand Up @@ -680,66 +680,6 @@ func TestWatchRemove(t *testing.T) {
CHMOD "/file"
`},

{"remove watched directory", func(t *testing.T, w *Watcher, tmp string) {
touch(t, tmp, "a")
touch(t, tmp, "b")
touch(t, tmp, "c")
touch(t, tmp, "d")
touch(t, tmp, "e")
touch(t, tmp, "f")
touch(t, tmp, "g")
mkdir(t, tmp, "h")
mkdir(t, tmp, "h", "a")
mkdir(t, tmp, "i")
mkdir(t, tmp, "i", "a")
mkdir(t, tmp, "j")
mkdir(t, tmp, "j", "a")
addWatch(t, w, tmp)
rmAll(t, tmp)
}, `
remove /
remove /a
remove /b
remove /c
remove /d
remove /e
remove /f
remove /g
remove /h
remove /i
remove /j

# TODO: this is broken; I've also seen (/i and /j missing):
# REMOVE "/"
# REMOVE "/a"
# REMOVE "/b"
# REMOVE "/c"
# REMOVE "/d"
# REMOVE "/e"
# REMOVE "/f"
# REMOVE "/g"
# WRITE "/h"
# WRITE "/h"
windows:
REMOVE "/"
REMOVE "/a"
REMOVE "/b"
REMOVE "/c"
REMOVE "/d"
REMOVE "/e"
REMOVE "/f"
REMOVE "/g"
REMOVE "/h"
REMOVE "/i"
REMOVE "/j"
WRITE "/h"
WRITE "/h"
WRITE "/i"
WRITE "/i"
WRITE "/j"
WRITE "/j"
`},

{"remove recursive", func(t *testing.T, w *Watcher, tmp string) {
recurseOnly(t)

Expand Down Expand Up @@ -778,6 +718,66 @@ func TestWatchRemove(t *testing.T) {
tt := tt
tt.run(t)
}

t.Run("remove watched directory", func(t *testing.T) {
t.Parallel()
tmp := t.TempDir()

w := newCollector(t)
w.collect(t)

touch(t, tmp, "a")
touch(t, tmp, "b")
touch(t, tmp, "c")
touch(t, tmp, "d")
touch(t, tmp, "e")
touch(t, tmp, "f")
touch(t, tmp, "g")
mkdir(t, tmp, "h")
mkdir(t, tmp, "h", "a")
mkdir(t, tmp, "i")
mkdir(t, tmp, "i", "a")
mkdir(t, tmp, "j")
mkdir(t, tmp, "j", "a")
addWatch(t, w.w, tmp)
rmAll(t, tmp)

if runtime.GOOS != "windows" {
cmpEvents(t, tmp, w.stop(t), newEvents(t, `
remove /
remove /a
remove /b
remove /c
remove /d
remove /e
remove /f
remove /g
remove /h
remove /i
remove /j`))
return
}

// ReadDirectoryChangesW gives undefined results: not all files are
// always present. So test only that 1) we got the directory itself, and
// 2) we don't get events for unspected files.
var (
events = w.stop(t)
found bool
)
for _, e := range events {
if e.Name == tmp && e.Has(Remove) {
found = true
continue
}
if filepath.Dir(e.Name) != tmp {
t.Errorf("unexpected event: %s", e)
}
}
if !found {
t.Fatalf("didn't see directory in:\n%s", events)
}
})
}

func TestWatchRecursive(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions mkdoc.zsh
Expand Up @@ -62,6 +62,11 @@ watcher=$(<<EOF
// Paths can be added as "C:\\path\\to\\dir", but forward slashes
// ("C:/path/to/dir") will also work.
//
// When a watched directory is removed it will always send an event for the
// directory itself, but may not send events for all files in that directory.
// Sometimes it will send events for all times, sometimes it will send no
// events, and often only for some files.
//
// The default buffer size is 64K, which is the largest value that is guaranteed
// to work with SMB filesystems. If you have many events in quick succession
// this may not be enough, and you will have to use [WithBufferSize] to increase
Expand Down