From 42e9219696d013f252e69d7f0cdea2925125edb1 Mon Sep 17 00:00:00 2001 From: Ichinose Shogo Date: Sat, 31 Jul 2021 16:13:10 +0900 Subject: [PATCH 01/20] introduce GitHub Actions --- .github/workflows/test.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..26bfb947 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: test +on: + push: + pull_request: + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + go: + - '1.16' + - '1.15' + runs-on: ${{ matrix.os }} + steps: + - name: setup Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + - name: checkout + uses: actions/checkout@v2 + + - name: test + run: | + go test --race ./... From ed6d2f5fc63eabe43a2247aedba089e8ed121709 Mon Sep 17 00:00:00 2001 From: Oliver Bristow Date: Sun, 1 Aug 2021 10:19:38 +0100 Subject: [PATCH 02/20] Add lint+vet+old versions to GitHub Action --- .github/workflows/test.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26bfb947..a6327ea9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,15 +15,49 @@ jobs: go: - '1.16' - '1.15' + - '1.14' + - '1.13' + - '1.12' + - '1.11' + # omitting these as they fail on macos+ubuntu with "kqueue.go:18:2: cannot find package "golang.org/x/sys/unix" in any of:" + # - '1.10' + # - '1.9' runs-on: ${{ matrix.os }} steps: - name: setup Go uses: actions/setup-go@v2 with: go-version: ${{ matrix.go }} + - name: checkout uses: actions/checkout@v2 - name: test run: | go test --race ./... + + lint: + runs-on: ubuntu-latest + steps: + - name: setup Go + uses: actions/setup-go@v2 + + - name: checkout + uses: actions/checkout@v2 + + - name: gofmt + run: | + test -z "$(gofmt -s -d . | tee /dev/stderr)" + + - name: vet + run: | + go vet ./... + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + continue-on-error: true + with: + version: v1.41.1 + # this is here as a workaround for https://github.com/golangci/golangci-lint-action/issues/244 + skip-pkg-cache: true + From 5ce1ba432e007af2088918b7147126dc03d8f717 Mon Sep 17 00:00:00 2001 From: Oliver Bristow Date: Sun, 1 Aug 2021 11:11:11 +0100 Subject: [PATCH 03/20] Remove Travis CI and references --- .travis.yml | 36 ------------------------------------ README.md | 6 +++--- 2 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a9c30165..00000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -sudo: false -language: go - -go: - - "stable" - - "1.11.x" - - "1.10.x" - - "1.9.x" - -matrix: - include: - - go: "stable" - env: GOLINT=true - allow_failures: - - go: tip - fast_finish: true - - -before_install: - - if [ ! -z "${GOLINT}" ]; then go get -u golang.org/x/lint/golint; fi - -script: - - go test --race ./... - -after_script: - - test -z "$(gofmt -s -l -w . | tee /dev/stderr)" - - if [ ! -z "${GOLINT}" ]; then echo running golint; golint --set_exit_status ./...; else echo skipping golint; fi - - go vet ./... - -os: - - linux - - osx - - windows - -notifications: - email: false diff --git a/README.md b/README.md index b2629e52..df57b1b2 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ Cross platform: Windows, Linux, BSD and macOS. | Adapter | OS | Status | | --------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -| inotify | Linux 2.6.27 or later, Android\* | Supported [![Build Status](https://travis-ci.org/fsnotify/fsnotify.svg?branch=master)](https://travis-ci.org/fsnotify/fsnotify) | -| kqueue | BSD, macOS, iOS\* | Supported [![Build Status](https://travis-ci.org/fsnotify/fsnotify.svg?branch=master)](https://travis-ci.org/fsnotify/fsnotify) | -| ReadDirectoryChangesW | Windows | Supported [![Build Status](https://travis-ci.org/fsnotify/fsnotify.svg?branch=master)](https://travis-ci.org/fsnotify/fsnotify) | +| inotify | Linux 2.6.27 or later, Android\* | Supported | +| kqueue | BSD, macOS, iOS\* | Supported | +| ReadDirectoryChangesW | Windows | Supported | | FSEvents | macOS | [Planned](https://github.com/fsnotify/fsnotify/issues/11) | | FEN | Solaris 11 | [In Progress](https://github.com/fsnotify/fsnotify/issues/12) | | fanotify | Linux 2.6.37+ | [Planned](https://github.com/fsnotify/fsnotify/issues/114) | From 2fb15b141f1a0fca5f8f3299b39880819d20f911 Mon Sep 17 00:00:00 2001 From: Nahum Shalman Date: Wed, 4 Aug 2021 15:46:51 -0400 Subject: [PATCH 04/20] Drop support/testing for Go 1.11 and earlier (#381) --- .github/workflows/test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a6327ea9..cb3d37d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,10 +18,6 @@ jobs: - '1.14' - '1.13' - '1.12' - - '1.11' - # omitting these as they fail on macos+ubuntu with "kqueue.go:18:2: cannot find package "golang.org/x/sys/unix" in any of:" - # - '1.10' - # - '1.9' runs-on: ${{ matrix.os }} steps: - name: setup Go From cc8365b12c22c1c4abf6970d6789c5187822830e Mon Sep 17 00:00:00 2001 From: Nahum Shalman Date: Wed, 4 Aug 2021 15:53:11 -0400 Subject: [PATCH 05/20] Update x/sys to latest (#379) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ff11e13f..f37d2c03 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/fsnotify/fsnotify go 1.13 -require golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 +require golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c diff --git a/go.sum b/go.sum index f60af985..0f478630 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 16f0d4292788daa58e79a55f8557ef20d3cdaa48 Mon Sep 17 00:00:00 2001 From: Ichinose Shogo Date: Thu, 5 Aug 2021 05:19:43 +0900 Subject: [PATCH 06/20] add //go:build lines + add 1.17.0-rc2 to test matrix (#377) --- .github/workflows/test.yml | 2 ++ fen.go | 1 + fsnotify.go | 1 + fsnotify_test.go | 1 + inotify.go | 1 + inotify_poller.go | 1 + inotify_poller_test.go | 1 + inotify_test.go | 1 + integration_test.go | 1 + kqueue.go | 1 + open_mode_bsd.go | 1 + open_mode_darwin.go | 1 + windows.go | 1 + 13 files changed, 14 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cb3d37d1..51b9e603 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,7 @@ jobs: - macos-latest - windows-latest go: + - '1.17.0-rc2' - '1.16' - '1.15' - '1.14' @@ -24,6 +25,7 @@ jobs: uses: actions/setup-go@v2 with: go-version: ${{ matrix.go }} + stable: false # for Go 1.17.0-rc2, it's not stable now. (2021-08-03) - name: checkout uses: actions/checkout@v2 diff --git a/fen.go b/fen.go index ced39cb8..b3ac3d8f 100644 --- a/fen.go +++ b/fen.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build solaris // +build solaris package fsnotify diff --git a/fsnotify.go b/fsnotify.go index 89cab046..0f4ee52e 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build !plan9 // +build !plan9 // Package fsnotify provides a platform-independent interface for file system notifications. diff --git a/fsnotify_test.go b/fsnotify_test.go index f9771d9d..51aa49c5 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build !plan9 // +build !plan9 package fsnotify diff --git a/inotify.go b/inotify.go index c56556f4..eb87699b 100644 --- a/inotify.go +++ b/inotify.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build linux // +build linux package fsnotify diff --git a/inotify_poller.go b/inotify_poller.go index b33f2b4d..e9ff9439 100644 --- a/inotify_poller.go +++ b/inotify_poller.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build linux // +build linux package fsnotify diff --git a/inotify_poller_test.go b/inotify_poller_test.go index 26623efe..c7475454 100644 --- a/inotify_poller_test.go +++ b/inotify_poller_test.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build linux // +build linux package fsnotify diff --git a/inotify_test.go b/inotify_test.go index 2c11d2ed..90c82b8e 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build linux // +build linux package fsnotify diff --git a/integration_test.go b/integration_test.go index 7096344d..fc09e03f 100644 --- a/integration_test.go +++ b/integration_test.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build !plan9 && !solaris // +build !plan9,!solaris package fsnotify diff --git a/kqueue.go b/kqueue.go index 86e76a3d..368f5b79 100644 --- a/kqueue.go +++ b/kqueue.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build freebsd || openbsd || netbsd || dragonfly || darwin // +build freebsd openbsd netbsd dragonfly darwin package fsnotify diff --git a/open_mode_bsd.go b/open_mode_bsd.go index 2306c462..36cc3845 100644 --- a/open_mode_bsd.go +++ b/open_mode_bsd.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build freebsd || openbsd || netbsd || dragonfly // +build freebsd openbsd netbsd dragonfly package fsnotify diff --git a/open_mode_darwin.go b/open_mode_darwin.go index 870c4d6d..98cd8476 100644 --- a/open_mode_darwin.go +++ b/open_mode_darwin.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build darwin // +build darwin package fsnotify diff --git a/windows.go b/windows.go index 09436f31..c02b75f7 100644 --- a/windows.go +++ b/windows.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build windows // +build windows package fsnotify From 82ee6f321d4a63a742fd51b5b2cda11dc50de692 Mon Sep 17 00:00:00 2001 From: Nahum Shalman Date: Tue, 17 Aug 2021 10:33:47 -0400 Subject: [PATCH 07/20] Update test matrix for go 1.17 stable release (#385) --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 51b9e603..a20673a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: - macos-latest - windows-latest go: - - '1.17.0-rc2' + - '1.17' - '1.16' - '1.15' - '1.14' @@ -25,7 +25,6 @@ jobs: uses: actions/setup-go@v2 with: go-version: ${{ matrix.go }} - stable: false # for Go 1.17.0-rc2, it's not stable now. (2021-08-03) - name: checkout uses: actions/checkout@v2 From e2e95171bc7c7402864e613c8b00a768fbcc2380 Mon Sep 17 00:00:00 2001 From: Oliver Bristow Date: Wed, 18 Aug 2021 22:08:44 +0100 Subject: [PATCH 08/20] Add AddRaw to not follow symlinks + Fix link folloing on Windows (#289) --- README.md | 13 +++++++- fen.go | 4 +-- fsnotify.go | 17 +++++++++++ fsnotify_test.go | 2 +- inotify.go | 6 ++-- inotify_test.go | 16 +++++----- integration_test.go | 73 +++++++++++++++++++++++++++++++++++++++++---- kqueue.go | 32 ++------------------ windows.go | 4 +-- 9 files changed, 116 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index df57b1b2..670f2cfc 100644 --- a/README.md +++ b/README.md @@ -72,10 +72,18 @@ func main() { } }() + // if this is a link, it will follow all the links and watch the file pointed to err = watcher.Add("/tmp/foo") if err != nil { log.Fatal(err) } + + // this will watch the link, rather than the file it points to + err = watcher.AddRaw("/tmp/link") + if err != nil { + log.Fatal(err) + } + <-done } ``` @@ -90,6 +98,10 @@ See [example_test.go](https://github.com/fsnotify/fsnotify/blob/master/example_t ## FAQ +**Are symlinks resolved?** +Symlinks are implicitly resolved by [`filepath.EvalSymlinks(path)`](https://golang.org/pkg/path/filepath/#EvalSymlinks) when `watcher.Add(name)` is used. If that is not desired, you can use `watcher.AddRaw(name)` to not follow any symlinks before watching. See [example_test.go](https://github.com/fsnotify/fsnotify/blob/master/example_test.go). + + **When a file is moved to another directory is it still being watched?** No (it shouldn't be, unless you are watching where it was moved to). @@ -127,4 +139,3 @@ fsnotify requires support from underlying OS to work. The current NFS protocol d * [notify](https://github.com/rjeczalik/notify) * [fsevents](https://github.com/fsnotify/fsevents) - diff --git a/fen.go b/fen.go index b3ac3d8f..325ece59 100644 --- a/fen.go +++ b/fen.go @@ -27,8 +27,8 @@ func (w *Watcher) Close() error { return nil } -// Add starts watching the named file or directory (non-recursively). -func (w *Watcher) Add(name string) error { +// AddRaw starts watching the named file or directory (non-recursively). Symlinks are not implicitly resolved. +func (w *Watcher) AddRaw(name string) error { return nil } diff --git a/fsnotify.go b/fsnotify.go index 0f4ee52e..5e240dc2 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -12,6 +12,7 @@ import ( "bytes" "errors" "fmt" + "path/filepath" ) // Event represents a single file system notification. @@ -67,3 +68,19 @@ func (e Event) String() string { var ( ErrEventOverflow = errors.New("fsnotify queue overflow") ) + +// Add starts watching the named file or directory (non-recursively). Symlinks are implicitly resolved. +func (w *Watcher) Add(name string) error { + rawPath, err := filepath.EvalSymlinks(name) + if err != nil { + return fmt.Errorf("error resolving %#v: %s", name, err) + } + err = w.AddRaw(rawPath) + if err != nil { + if name != rawPath { + return fmt.Errorf("error adding %#v for %#v: %s", rawPath, name, err) + } + return err + } + return nil +} diff --git a/fsnotify_test.go b/fsnotify_test.go index 51aa49c5..5751fbab 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -52,7 +52,7 @@ func TestWatcherClose(t *testing.T) { name := tempMkFile(t, "") w := newWatcher(t) - err := w.Add(name) + err := w.AddRaw(name) if err != nil { t.Fatal(err) } diff --git a/inotify.go b/inotify.go index eb87699b..994daf09 100644 --- a/inotify.go +++ b/inotify.go @@ -88,8 +88,8 @@ func (w *Watcher) Close() error { return nil } -// Add starts watching the named file or directory (non-recursively). -func (w *Watcher) Add(name string) error { +// AddRaw starts watching the named file or directory (non-recursively). Symlinks are not implicitly resolved. +func (w *Watcher) AddRaw(name string) error { name = filepath.Clean(name) if w.isClosed() { return errors.New("inotify instance already closed") @@ -97,7 +97,7 @@ func (w *Watcher) Add(name string) error { const agnosticEvents = unix.IN_MOVED_TO | unix.IN_MOVED_FROM | unix.IN_CREATE | unix.IN_ATTRIB | unix.IN_MODIFY | - unix.IN_MOVE_SELF | unix.IN_DELETE | unix.IN_DELETE_SELF + unix.IN_MOVE_SELF | unix.IN_DELETE | unix.IN_DELETE_SELF | unix.IN_DONT_FOLLOW var flags uint32 = agnosticEvents diff --git a/inotify_test.go b/inotify_test.go index 90c82b8e..8cd1cfd5 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -54,7 +54,7 @@ func TestInotifyCloseSlightlyLaterWithWatch(t *testing.T) { if err != nil { t.Fatalf("Failed to create watcher") } - w.Add(testDir) + w.AddRaw(testDir) // Wait until readEvents has reached unix.Read, and Close. <-time.After(50 * time.Millisecond) @@ -74,7 +74,7 @@ func TestInotifyCloseAfterRead(t *testing.T) { t.Fatalf("Failed to create watcher") } - err = w.Add(testDir) + err = w.AddRaw(testDir) if err != nil { t.Fatalf("Failed to add .") } @@ -121,7 +121,7 @@ func TestInotifyCloseCreate(t *testing.T) { } defer w.Close() - err = w.Add(testDir) + err = w.AddRaw(testDir) if err != nil { t.Fatalf("Failed to add testDir: %v", err) } @@ -149,7 +149,7 @@ func TestInotifyCloseCreate(t *testing.T) { } <-time.After(50 * time.Millisecond) - err = w.Add(testDir) + err = w.AddRaw(testDir) if err != nil { t.Fatalf("Error adding testDir again: %v", err) } @@ -170,7 +170,7 @@ func TestInotifyStress(t *testing.T) { } defer w.Close() - err = w.Add(testDir) + err = w.AddRaw(testDir) if err != nil { t.Fatalf("Failed to add testDir: %v", err) } @@ -290,7 +290,7 @@ func TestInotifyRemoveTwice(t *testing.T) { } defer w.Close() - err = w.Add(testFile) + err = w.AddRaw(testFile) if err != nil { t.Fatalf("Failed to add testFile: %v", err) } @@ -332,7 +332,7 @@ func TestInotifyInnerMapLength(t *testing.T) { } defer w.Close() - err = w.Add(testFile) + err = w.AddRaw(testFile) if err != nil { t.Fatalf("Failed to add testFile: %v", err) } @@ -384,7 +384,7 @@ func TestInotifyOverflow(t *testing.T) { t.Fatalf("Cannot create subdir: %v", err) } - err = w.Add(testSubdir) + err = w.AddRaw(testSubdir) if err != nil { t.Fatalf("Failed to add subdir: %v", err) } diff --git a/integration_test.go b/integration_test.go index fc09e03f..cf1b8cff 100644 --- a/integration_test.go +++ b/integration_test.go @@ -66,8 +66,8 @@ func newWatcher(t *testing.T) *Watcher { // addWatch adds a watch for a directory func addWatch(t *testing.T, watcher *Watcher, dir string) { - if err := watcher.Add(dir); err != nil { - t.Fatalf("watcher.Add(%q) failed: %s", dir, err) + if err := watcher.AddRaw(dir); err != nil { + t.Fatalf("watcher.AddRaw(%q) failed: %s", dir, err) } } @@ -1008,11 +1008,74 @@ func TestFsnotifyClose(t *testing.T) { testDir := tempMkdir(t) defer os.RemoveAll(testDir) - if err := watcher.Add(testDir); err == nil { + if err := watcher.AddRaw(testDir); err == nil { t.Fatal("expected error on Watch() after Close(), got nil") } } +func TestSymlinkNotResolved(t *testing.T) { + testDir := tempMkdir(t) + file1 := filepath.Join(testDir, "file1") + file2 := filepath.Join(testDir, "file2") + link := filepath.Join(testDir, "link") + + f1, err := os.Create(file1) + if err != nil { + t.Fatalf("Failed to create file1: %s", err) + } + defer f1.Close() + if _, err := os.Create(file2); err != nil { + t.Fatalf("Failed to create file2: %s", err) + } + + // symlink works for Windows too + if err := os.Symlink(file1, link); err != nil { + t.Fatalf("Failed to create symlink: %s", err) + } + + w, err := NewWatcher() + if err != nil { + t.Fatalf("Failed to create watcher") + } + + err = w.AddRaw(link) + if err != nil { + t.Fatalf("Failed to add link: %s", err) + } + + // change file 1 - no event + f1.Write([]byte("Hello")) + f1.Sync() + // XXX(Code0x58): doing a create here shows a CHMOD event on mac - is that an issue? + + select { + case event := <-w.Events: + t.Fatalf("Event from watcher: %v", event) + case err := <-w.Errors: + t.Fatalf("Error from watcher: %v", err) + case <-time.After(50 * time.Millisecond): + } + + // ~atomic link change event + tmpLink := filepath.Join(testDir, "tmp-link") + if err := os.Symlink(file2, tmpLink); err != nil { + t.Fatalf("Failed to create symlink: %s", err) + } + + if err := os.Rename(tmpLink, link); err != nil { + t.Fatalf("Failed to replace symlink: %s", err) + } + + select { + case _ = <-w.Events: + case err := <-w.Errors: + t.Fatalf("Error from watcher: %v", err) + case <-time.After(50 * time.Millisecond): + t.Fatalf("Took too long to wait for event") + } + +} + func TestFsnotifyFakeSymlink(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("symlinks don't work on Windows.") @@ -1174,7 +1237,7 @@ func TestClose(t *testing.T) { defer os.RemoveAll(testDir) watcher := newWatcher(t) - if err := watcher.Add(testDir); err != nil { + if err := watcher.AddRaw(testDir); err != nil { t.Fatalf("Expected no error on Add, got %v", err) } err := watcher.Close() @@ -1195,7 +1258,7 @@ func TestRemoveWithClose(t *testing.T) { tempFiles = append(tempFiles, tempMkFile(t, testDir)) } watcher := newWatcher(t) - if err := watcher.Add(testDir); err != nil { + if err := watcher.AddRaw(testDir); err != nil { t.Fatalf("Expected no error on Add, got %v", err) } startC, stopC := make(chan struct{}), make(chan struct{}) diff --git a/kqueue.go b/kqueue.go index 368f5b79..caecacb5 100644 --- a/kqueue.go +++ b/kqueue.go @@ -91,8 +91,8 @@ func (w *Watcher) Close() error { return nil } -// Add starts watching the named file or directory (non-recursively). -func (w *Watcher) Add(name string) error { +// AddRaw starts watching the named file or directory (non-recursively). Symlinks are not implicitly resolved. +func (w *Watcher) AddRaw(name string) error { w.mu.Lock() w.externalWatches[name] = true w.mu.Unlock() @@ -190,33 +190,7 @@ func (w *Watcher) addWatch(name string, flags uint32) (string, error) { return "", nil } - // Follow Symlinks - // Unfortunately, Linux can add bogus symlinks to watch list without - // issue, and Windows can't do symlinks period (AFAIK). To maintain - // consistency, we will act like everything is fine. There will simply - // be no file events for broken symlinks. - // Hence the returns of nil on errors. - if fi.Mode()&os.ModeSymlink == os.ModeSymlink { - name, err = filepath.EvalSymlinks(name) - if err != nil { - return "", nil - } - - w.mu.Lock() - _, alreadyWatching = w.watches[name] - w.mu.Unlock() - - if alreadyWatching { - return name, nil - } - - fi, err = os.Lstat(name) - if err != nil { - return "", nil - } - } - - watchfd, err = unix.Open(name, openMode, 0700) + watchfd, err = unix.Open(name, openMode|unix.O_SYMLINK, 0700) if watchfd == -1 { return "", err } diff --git a/windows.go b/windows.go index c02b75f7..7dd51481 100644 --- a/windows.go +++ b/windows.go @@ -64,8 +64,8 @@ func (w *Watcher) Close() error { return <-ch } -// Add starts watching the named file or directory (non-recursively). -func (w *Watcher) Add(name string) error { +// AddRaw starts watching the named file or directory (non-recursively). Symlinks are not implicitly resolved. +func (w *Watcher) AddRaw(name string) error { if w.isClosed { return errors.New("watcher already closed") } From 08848a0f17ce8e0695b5bf6f17a5ef7d13653c30 Mon Sep 17 00:00:00 2001 From: Oliver Bristow Date: Wed, 18 Aug 2021 23:48:34 +0100 Subject: [PATCH 09/20] v1.5.0 preparation (#380) --- .mailmap | 2 ++ AUTHORS | 16 +++++++++++++--- CHANGELOG.md | 11 +++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .mailmap diff --git a/.mailmap b/.mailmap new file mode 100644 index 00000000..a04f2907 --- /dev/null +++ b/.mailmap @@ -0,0 +1,2 @@ +Chris Howey +Nathan Youngman <4566+nathany@users.noreply.github.com> diff --git a/AUTHORS b/AUTHORS index 5ab5d41c..6cbabe5e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,35 +4,44 @@ # You can update this list using the following command: # -# $ git shortlog -se | awk '{print $2 " " $3 " " $4}' +# $ (head -n10 AUTHORS && git shortlog -se | sed -E 's/^\s+[0-9]+\t//') | tee AUTHORS # Please keep the list sorted. Aaron L Adrien Bustany +Alexey Kazakov Amit Krishnan Anmol Sethi Bjørn Erik Pedersen +Brian Goff Bruno Bigras Caleb Spare Case Nelson -Chris Howey +Chris Howey Christoffer Buchholz Daniel Wagner-Hall Dave Cheney +Eric Lin Evan Phoenix Francisco Souza +Gautam Dey Hari haran -John C Barstow +Ichinose Shogo +Johannes Ebke +John C Barstow Kelvin Fo Ken-ichirou MATSUZAWA Matt Layher +Matthias Stone Nathan Youngman Nickolai Zeldovich +Oliver Bristow Patrick Paul Hammond Pawel Knap Pieter Droogendijk +Pratik Shinde Pursuit92 Riku Voipio Rob Figueiredo @@ -41,6 +50,7 @@ Slawek Ligus Soge Zhang Tiffany Jernigan Tilak Sharma +Tobias Klauser Tom Payne Travis Cline Tudor Golubenco diff --git a/CHANGELOG.md b/CHANGELOG.md index be4d7ea2..e2689213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## v1.5.0 / 2021-08-20 + +* Go: Increase minimum required version to Go 1.12 [#381](https://github.com/fsnotify/fsnotify/pull/381) +* Feature: Add AddRaw method which does not follow symlinks when adding a watch [#289](https://github.com/fsnotify/fsnotify/pull/298) +* Windows: Follow symlinks by default like on all other systems [#289](https://github.com/fsnotify/fsnotify/pull/289) +* CI: Use GitHub Actions for CI and cover go 1.12-1.17 + [#378](https://github.com/fsnotify/fsnotify/pull/378) + [#381](https://github.com/fsnotify/fsnotify/pull/381) + [#385](https://github.com/fsnotify/fsnotify/pull/385) +* Go 1.14+: Fix unsafe pointer conversion [#325](https://github.com/fsnotify/fsnotify/pull/325) + ## v1.4.7 / 2018-01-09 * BSD/macOS: Fix possible deadlock on closing the watcher on kqueue (thanks @nhooyr and @glycerine) From dfdb6450cd2695cd4592048534383bd0c4163a95 Mon Sep 17 00:00:00 2001 From: Nathan Youngman <4566+nathany@users.noreply.github.com> Date: Mon, 23 Aug 2021 18:34:28 -0600 Subject: [PATCH 10/20] revise pull request template --- .github/PULL_REQUEST_TEMPLATE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 64ddf7ce..6d5eb8be 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,3 +1,5 @@ +NOTE: Please do not open a pull request that adds or changes the public API without giving consideration to all supported operating systems. + #### What does this pull request do? From b98ede5aab008b4c373d4341c75e5b74a56dfaae Mon Sep 17 00:00:00 2001 From: Nathan Youngman <4566+nathany@users.noreply.github.com> Date: Tue, 24 Aug 2021 13:09:43 -0600 Subject: [PATCH 11/20] Revert "Add AddRaw to not follow symlinks + Fix link folloing on Windows (#289)" This reverts commit e2e95171bc7c7402864e613c8b00a768fbcc2380. --- README.md | 13 +------- fen.go | 4 +-- fsnotify.go | 17 ----------- fsnotify_test.go | 2 +- inotify.go | 6 ++-- inotify_test.go | 16 +++++----- integration_test.go | 73 ++++----------------------------------------- kqueue.go | 32 ++++++++++++++++++-- windows.go | 4 +-- 9 files changed, 51 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index 670f2cfc..df57b1b2 100644 --- a/README.md +++ b/README.md @@ -72,18 +72,10 @@ func main() { } }() - // if this is a link, it will follow all the links and watch the file pointed to err = watcher.Add("/tmp/foo") if err != nil { log.Fatal(err) } - - // this will watch the link, rather than the file it points to - err = watcher.AddRaw("/tmp/link") - if err != nil { - log.Fatal(err) - } - <-done } ``` @@ -98,10 +90,6 @@ See [example_test.go](https://github.com/fsnotify/fsnotify/blob/master/example_t ## FAQ -**Are symlinks resolved?** -Symlinks are implicitly resolved by [`filepath.EvalSymlinks(path)`](https://golang.org/pkg/path/filepath/#EvalSymlinks) when `watcher.Add(name)` is used. If that is not desired, you can use `watcher.AddRaw(name)` to not follow any symlinks before watching. See [example_test.go](https://github.com/fsnotify/fsnotify/blob/master/example_test.go). - - **When a file is moved to another directory is it still being watched?** No (it shouldn't be, unless you are watching where it was moved to). @@ -139,3 +127,4 @@ fsnotify requires support from underlying OS to work. The current NFS protocol d * [notify](https://github.com/rjeczalik/notify) * [fsevents](https://github.com/fsnotify/fsevents) + diff --git a/fen.go b/fen.go index 325ece59..b3ac3d8f 100644 --- a/fen.go +++ b/fen.go @@ -27,8 +27,8 @@ func (w *Watcher) Close() error { return nil } -// AddRaw starts watching the named file or directory (non-recursively). Symlinks are not implicitly resolved. -func (w *Watcher) AddRaw(name string) error { +// Add starts watching the named file or directory (non-recursively). +func (w *Watcher) Add(name string) error { return nil } diff --git a/fsnotify.go b/fsnotify.go index 5e240dc2..0f4ee52e 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -12,7 +12,6 @@ import ( "bytes" "errors" "fmt" - "path/filepath" ) // Event represents a single file system notification. @@ -68,19 +67,3 @@ func (e Event) String() string { var ( ErrEventOverflow = errors.New("fsnotify queue overflow") ) - -// Add starts watching the named file or directory (non-recursively). Symlinks are implicitly resolved. -func (w *Watcher) Add(name string) error { - rawPath, err := filepath.EvalSymlinks(name) - if err != nil { - return fmt.Errorf("error resolving %#v: %s", name, err) - } - err = w.AddRaw(rawPath) - if err != nil { - if name != rawPath { - return fmt.Errorf("error adding %#v for %#v: %s", rawPath, name, err) - } - return err - } - return nil -} diff --git a/fsnotify_test.go b/fsnotify_test.go index 5751fbab..51aa49c5 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -52,7 +52,7 @@ func TestWatcherClose(t *testing.T) { name := tempMkFile(t, "") w := newWatcher(t) - err := w.AddRaw(name) + err := w.Add(name) if err != nil { t.Fatal(err) } diff --git a/inotify.go b/inotify.go index 994daf09..eb87699b 100644 --- a/inotify.go +++ b/inotify.go @@ -88,8 +88,8 @@ func (w *Watcher) Close() error { return nil } -// AddRaw starts watching the named file or directory (non-recursively). Symlinks are not implicitly resolved. -func (w *Watcher) AddRaw(name string) error { +// Add starts watching the named file or directory (non-recursively). +func (w *Watcher) Add(name string) error { name = filepath.Clean(name) if w.isClosed() { return errors.New("inotify instance already closed") @@ -97,7 +97,7 @@ func (w *Watcher) AddRaw(name string) error { const agnosticEvents = unix.IN_MOVED_TO | unix.IN_MOVED_FROM | unix.IN_CREATE | unix.IN_ATTRIB | unix.IN_MODIFY | - unix.IN_MOVE_SELF | unix.IN_DELETE | unix.IN_DELETE_SELF | unix.IN_DONT_FOLLOW + unix.IN_MOVE_SELF | unix.IN_DELETE | unix.IN_DELETE_SELF var flags uint32 = agnosticEvents diff --git a/inotify_test.go b/inotify_test.go index 8cd1cfd5..90c82b8e 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -54,7 +54,7 @@ func TestInotifyCloseSlightlyLaterWithWatch(t *testing.T) { if err != nil { t.Fatalf("Failed to create watcher") } - w.AddRaw(testDir) + w.Add(testDir) // Wait until readEvents has reached unix.Read, and Close. <-time.After(50 * time.Millisecond) @@ -74,7 +74,7 @@ func TestInotifyCloseAfterRead(t *testing.T) { t.Fatalf("Failed to create watcher") } - err = w.AddRaw(testDir) + err = w.Add(testDir) if err != nil { t.Fatalf("Failed to add .") } @@ -121,7 +121,7 @@ func TestInotifyCloseCreate(t *testing.T) { } defer w.Close() - err = w.AddRaw(testDir) + err = w.Add(testDir) if err != nil { t.Fatalf("Failed to add testDir: %v", err) } @@ -149,7 +149,7 @@ func TestInotifyCloseCreate(t *testing.T) { } <-time.After(50 * time.Millisecond) - err = w.AddRaw(testDir) + err = w.Add(testDir) if err != nil { t.Fatalf("Error adding testDir again: %v", err) } @@ -170,7 +170,7 @@ func TestInotifyStress(t *testing.T) { } defer w.Close() - err = w.AddRaw(testDir) + err = w.Add(testDir) if err != nil { t.Fatalf("Failed to add testDir: %v", err) } @@ -290,7 +290,7 @@ func TestInotifyRemoveTwice(t *testing.T) { } defer w.Close() - err = w.AddRaw(testFile) + err = w.Add(testFile) if err != nil { t.Fatalf("Failed to add testFile: %v", err) } @@ -332,7 +332,7 @@ func TestInotifyInnerMapLength(t *testing.T) { } defer w.Close() - err = w.AddRaw(testFile) + err = w.Add(testFile) if err != nil { t.Fatalf("Failed to add testFile: %v", err) } @@ -384,7 +384,7 @@ func TestInotifyOverflow(t *testing.T) { t.Fatalf("Cannot create subdir: %v", err) } - err = w.AddRaw(testSubdir) + err = w.Add(testSubdir) if err != nil { t.Fatalf("Failed to add subdir: %v", err) } diff --git a/integration_test.go b/integration_test.go index cf1b8cff..fc09e03f 100644 --- a/integration_test.go +++ b/integration_test.go @@ -66,8 +66,8 @@ func newWatcher(t *testing.T) *Watcher { // addWatch adds a watch for a directory func addWatch(t *testing.T, watcher *Watcher, dir string) { - if err := watcher.AddRaw(dir); err != nil { - t.Fatalf("watcher.AddRaw(%q) failed: %s", dir, err) + if err := watcher.Add(dir); err != nil { + t.Fatalf("watcher.Add(%q) failed: %s", dir, err) } } @@ -1008,74 +1008,11 @@ func TestFsnotifyClose(t *testing.T) { testDir := tempMkdir(t) defer os.RemoveAll(testDir) - if err := watcher.AddRaw(testDir); err == nil { + if err := watcher.Add(testDir); err == nil { t.Fatal("expected error on Watch() after Close(), got nil") } } -func TestSymlinkNotResolved(t *testing.T) { - testDir := tempMkdir(t) - file1 := filepath.Join(testDir, "file1") - file2 := filepath.Join(testDir, "file2") - link := filepath.Join(testDir, "link") - - f1, err := os.Create(file1) - if err != nil { - t.Fatalf("Failed to create file1: %s", err) - } - defer f1.Close() - if _, err := os.Create(file2); err != nil { - t.Fatalf("Failed to create file2: %s", err) - } - - // symlink works for Windows too - if err := os.Symlink(file1, link); err != nil { - t.Fatalf("Failed to create symlink: %s", err) - } - - w, err := NewWatcher() - if err != nil { - t.Fatalf("Failed to create watcher") - } - - err = w.AddRaw(link) - if err != nil { - t.Fatalf("Failed to add link: %s", err) - } - - // change file 1 - no event - f1.Write([]byte("Hello")) - f1.Sync() - // XXX(Code0x58): doing a create here shows a CHMOD event on mac - is that an issue? - - select { - case event := <-w.Events: - t.Fatalf("Event from watcher: %v", event) - case err := <-w.Errors: - t.Fatalf("Error from watcher: %v", err) - case <-time.After(50 * time.Millisecond): - } - - // ~atomic link change event - tmpLink := filepath.Join(testDir, "tmp-link") - if err := os.Symlink(file2, tmpLink); err != nil { - t.Fatalf("Failed to create symlink: %s", err) - } - - if err := os.Rename(tmpLink, link); err != nil { - t.Fatalf("Failed to replace symlink: %s", err) - } - - select { - case _ = <-w.Events: - case err := <-w.Errors: - t.Fatalf("Error from watcher: %v", err) - case <-time.After(50 * time.Millisecond): - t.Fatalf("Took too long to wait for event") - } - -} - func TestFsnotifyFakeSymlink(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("symlinks don't work on Windows.") @@ -1237,7 +1174,7 @@ func TestClose(t *testing.T) { defer os.RemoveAll(testDir) watcher := newWatcher(t) - if err := watcher.AddRaw(testDir); err != nil { + if err := watcher.Add(testDir); err != nil { t.Fatalf("Expected no error on Add, got %v", err) } err := watcher.Close() @@ -1258,7 +1195,7 @@ func TestRemoveWithClose(t *testing.T) { tempFiles = append(tempFiles, tempMkFile(t, testDir)) } watcher := newWatcher(t) - if err := watcher.AddRaw(testDir); err != nil { + if err := watcher.Add(testDir); err != nil { t.Fatalf("Expected no error on Add, got %v", err) } startC, stopC := make(chan struct{}), make(chan struct{}) diff --git a/kqueue.go b/kqueue.go index caecacb5..368f5b79 100644 --- a/kqueue.go +++ b/kqueue.go @@ -91,8 +91,8 @@ func (w *Watcher) Close() error { return nil } -// AddRaw starts watching the named file or directory (non-recursively). Symlinks are not implicitly resolved. -func (w *Watcher) AddRaw(name string) error { +// Add starts watching the named file or directory (non-recursively). +func (w *Watcher) Add(name string) error { w.mu.Lock() w.externalWatches[name] = true w.mu.Unlock() @@ -190,7 +190,33 @@ func (w *Watcher) addWatch(name string, flags uint32) (string, error) { return "", nil } - watchfd, err = unix.Open(name, openMode|unix.O_SYMLINK, 0700) + // Follow Symlinks + // Unfortunately, Linux can add bogus symlinks to watch list without + // issue, and Windows can't do symlinks period (AFAIK). To maintain + // consistency, we will act like everything is fine. There will simply + // be no file events for broken symlinks. + // Hence the returns of nil on errors. + if fi.Mode()&os.ModeSymlink == os.ModeSymlink { + name, err = filepath.EvalSymlinks(name) + if err != nil { + return "", nil + } + + w.mu.Lock() + _, alreadyWatching = w.watches[name] + w.mu.Unlock() + + if alreadyWatching { + return name, nil + } + + fi, err = os.Lstat(name) + if err != nil { + return "", nil + } + } + + watchfd, err = unix.Open(name, openMode, 0700) if watchfd == -1 { return "", err } diff --git a/windows.go b/windows.go index 7dd51481..c02b75f7 100644 --- a/windows.go +++ b/windows.go @@ -64,8 +64,8 @@ func (w *Watcher) Close() error { return <-ch } -// AddRaw starts watching the named file or directory (non-recursively). Symlinks are not implicitly resolved. -func (w *Watcher) AddRaw(name string) error { +// Add starts watching the named file or directory (non-recursively). +func (w *Watcher) Add(name string) error { if w.isClosed { return errors.New("watcher already closed") } From 466b39d216616549a37ee93c7c47775f6a010790 Mon Sep 17 00:00:00 2001 From: Nathan Youngman <4566+nathany@users.noreply.github.com> Date: Tue, 24 Aug 2021 13:33:30 -0600 Subject: [PATCH 12/20] prepare 1.5.1, retract 1.5.0 --- CHANGELOG.md | 107 ++++++++++++++++++++++++++++----------------------- go.mod | 2 + 2 files changed, 61 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2689213..a438fe4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ # Changelog -## v1.5.0 / 2021-08-20 +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [1.5.1] - 2021-08-24 + +* Revert Add AddRaw to not follow symlinks + +## [1.5.0] - 2021-08-20 * Go: Increase minimum required version to Go 1.12 [#381](https://github.com/fsnotify/fsnotify/pull/381) * Feature: Add AddRaw method which does not follow symlinks when adding a watch [#289](https://github.com/fsnotify/fsnotify/pull/298) @@ -11,7 +22,7 @@ [#385](https://github.com/fsnotify/fsnotify/pull/385) * Go 1.14+: Fix unsafe pointer conversion [#325](https://github.com/fsnotify/fsnotify/pull/325) -## v1.4.7 / 2018-01-09 +## [1.4.7] - 2018-01-09 * BSD/macOS: Fix possible deadlock on closing the watcher on kqueue (thanks @nhooyr and @glycerine) * Tests: Fix missing verb on format string (thanks @rchiossi) @@ -21,62 +32,62 @@ * Linux: Properly handle inotify's IN_Q_OVERFLOW event (thanks @zeldovich) * Docs: replace references to OS X with macOS -## v1.4.2 / 2016-10-10 +## [1.4.2] - 2016-10-10 * Linux: use InotifyInit1 with IN_CLOEXEC to stop leaking a file descriptor to a child process when using fork/exec [#178](https://github.com/fsnotify/fsnotify/pull/178) (thanks @pattyshack) -## v1.4.1 / 2016-10-04 +## [1.4.1] - 2016-10-04 * Fix flaky inotify stress test on Linux [#177](https://github.com/fsnotify/fsnotify/pull/177) (thanks @pattyshack) -## v1.4.0 / 2016-10-01 +## [1.4.0] - 2016-10-01 * add a String() method to Event.Op [#165](https://github.com/fsnotify/fsnotify/pull/165) (thanks @oozie) -## v1.3.1 / 2016-06-28 +## [1.3.1] - 2016-06-28 * Windows: fix for double backslash when watching the root of a drive [#151](https://github.com/fsnotify/fsnotify/issues/151) (thanks @brunoqc) -## v1.3.0 / 2016-04-19 +## [1.3.0] - 2016-04-19 * Support linux/arm64 by [patching](https://go-review.googlesource.com/#/c/21971/) x/sys/unix and switching to to it from syscall (thanks @suihkulokki) [#135](https://github.com/fsnotify/fsnotify/pull/135) -## v1.2.10 / 2016-03-02 +## [1.2.10] - 2016-03-02 * Fix golint errors in windows.go [#121](https://github.com/fsnotify/fsnotify/pull/121) (thanks @tiffanyfj) -## v1.2.9 / 2016-01-13 +## [1.2.9] - 2016-01-13 kqueue: Fix logic for CREATE after REMOVE [#111](https://github.com/fsnotify/fsnotify/pull/111) (thanks @bep) -## v1.2.8 / 2015-12-17 +## [1.2.8] - 2015-12-17 * kqueue: fix race condition in Close [#105](https://github.com/fsnotify/fsnotify/pull/105) (thanks @djui for reporting the issue and @ppknap for writing a failing test) * inotify: fix race in test * enable race detection for continuous integration (Linux, Mac, Windows) -## v1.2.5 / 2015-10-17 +## [1.2.5] - 2015-10-17 * inotify: use epoll_create1 for arm64 support (requires Linux 2.6.27 or later) [#100](https://github.com/fsnotify/fsnotify/pull/100) (thanks @suihkulokki) * inotify: fix path leaks [#73](https://github.com/fsnotify/fsnotify/pull/73) (thanks @chamaken) * kqueue: watch for rename events on subdirectories [#83](https://github.com/fsnotify/fsnotify/pull/83) (thanks @guotie) * kqueue: avoid infinite loops from symlinks cycles [#101](https://github.com/fsnotify/fsnotify/pull/101) (thanks @illicitonion) -## v1.2.1 / 2015-10-14 +## [1.2.1] - 2015-10-14 * kqueue: don't watch named pipes [#98](https://github.com/fsnotify/fsnotify/pull/98) (thanks @evanphx) -## v1.2.0 / 2015-02-08 +## [1.2.0] - 2015-02-08 * inotify: use epoll to wake up readEvents [#66](https://github.com/fsnotify/fsnotify/pull/66) (thanks @PieterD) * inotify: closing watcher should now always shut down goroutine [#63](https://github.com/fsnotify/fsnotify/pull/63) (thanks @PieterD) * kqueue: close kqueue after removing watches, fixes [#59](https://github.com/fsnotify/fsnotify/issues/59) -## v1.1.1 / 2015-02-05 +## [1.1.1] - 2015-02-05 * inotify: Retry read on EINTR [#61](https://github.com/fsnotify/fsnotify/issues/61) (thanks @PieterD) -## v1.1.0 / 2014-12-12 +## [1.1.0] - 2014-12-12 * kqueue: rework internals [#43](https://github.com/fsnotify/fsnotify/pull/43) * add low-level functions @@ -88,22 +99,22 @@ kqueue: Fix logic for CREATE after REMOVE [#111](https://github.com/fsnotify/fsn * kqueue: fix regression in rework causing subdirectories to be watched [#48](https://github.com/fsnotify/fsnotify/issues/48) * kqueue: cleanup internal watch before sending remove event [#51](https://github.com/fsnotify/fsnotify/issues/51) -## v1.0.4 / 2014-09-07 +## [1.0.4] - 2014-09-07 * kqueue: add dragonfly to the build tags. * Rename source code files, rearrange code so exported APIs are at the top. * Add done channel to example code. [#37](https://github.com/fsnotify/fsnotify/pull/37) (thanks @chenyukang) -## v1.0.3 / 2014-08-19 +## [1.0.3] - 2014-08-19 * [Fix] Windows MOVED_TO now translates to Create like on BSD and Linux. [#36](https://github.com/fsnotify/fsnotify/issues/36) -## v1.0.2 / 2014-08-17 +## [1.0.2] - 2014-08-17 * [Fix] Missing create events on macOS. [#14](https://github.com/fsnotify/fsnotify/issues/14) (thanks @zhsso) * [Fix] Make ./path and path equivalent. (thanks @zhsso) -## v1.0.0 / 2014-08-15 +## [1.0.0] - 2014-08-15 * [API] Remove AddWatch on Windows, use Add. * Improve documentation for exported identifiers. [#30](https://github.com/fsnotify/fsnotify/issues/30) @@ -157,51 +168,51 @@ kqueue: Fix logic for CREATE after REMOVE [#111](https://github.com/fsnotify/fsn * no tests for the current implementation * not fully implemented on Windows [#93](https://github.com/howeyc/fsnotify/issues/93#issuecomment-39285195) -## v0.9.3 / 2014-12-31 +## [0.9.3] - 2014-12-31 * kqueue: cleanup internal watch before sending remove event [#51](https://github.com/fsnotify/fsnotify/issues/51) -## v0.9.2 / 2014-08-17 +## [0.9.2] - 2014-08-17 * [Backport] Fix missing create events on macOS. [#14](https://github.com/fsnotify/fsnotify/issues/14) (thanks @zhsso) -## v0.9.1 / 2014-06-12 +## [0.9.1] - 2014-06-12 * Fix data race on kevent buffer (thanks @tilaks) [#98](https://github.com/howeyc/fsnotify/pull/98) -## v0.9.0 / 2014-01-17 +## [0.9.0] - 2014-01-17 * IsAttrib() for events that only concern a file's metadata [#79][] (thanks @abustany) * [Fix] kqueue: fix deadlock [#77][] (thanks @cespare) * [NOTICE] Development has moved to `code.google.com/p/go.exp/fsnotify` in preparation for inclusion in the Go standard library. -## v0.8.12 / 2013-11-13 +## [0.8.12] - 2013-11-13 * [API] Remove FD_SET and friends from Linux adapter -## v0.8.11 / 2013-11-02 +## [0.8.11] - 2013-11-02 * [Doc] Add Changelog [#72][] (thanks @nathany) * [Doc] Spotlight and double modify events on macOS [#62][] (reported by @paulhammond) -## v0.8.10 / 2013-10-19 +## [0.8.10] - 2013-10-19 * [Fix] kqueue: remove file watches when parent directory is removed [#71][] (reported by @mdwhatcott) * [Fix] kqueue: race between Close and readEvents [#70][] (reported by @bernerdschaefer) * [Doc] specify OS-specific limits in README (thanks @debrando) -## v0.8.9 / 2013-09-08 +## [0.8.9] - 2013-09-08 * [Doc] Contributing (thanks @nathany) * [Doc] update package path in example code [#63][] (thanks @paulhammond) * [Doc] GoCI badge in README (Linux only) [#60][] * [Doc] Cross-platform testing with Vagrant [#59][] (thanks @nathany) -## v0.8.8 / 2013-06-17 +## [0.8.8] - 2013-06-17 * [Fix] Windows: handle `ERROR_MORE_DATA` on Windows [#49][] (thanks @jbowtie) -## v0.8.7 / 2013-06-03 +## [0.8.7] - 2013-06-03 * [API] Make syscall flags internal * [Fix] inotify: ignore event changes @@ -209,74 +220,74 @@ kqueue: Fix logic for CREATE after REMOVE [#111](https://github.com/fsnotify/fsn * [Fix] tests on Windows * lower case error messages -## v0.8.6 / 2013-05-23 +## [0.8.6] - 2013-05-23 * kqueue: Use EVT_ONLY flag on Darwin * [Doc] Update README with full example -## v0.8.5 / 2013-05-09 +## [0.8.5] - 2013-05-09 * [Fix] inotify: allow monitoring of "broken" symlinks (thanks @tsg) -## v0.8.4 / 2013-04-07 +## [0.8.4] - 2013-04-07 * [Fix] kqueue: watch all file events [#40][] (thanks @ChrisBuchholz) -## v0.8.3 / 2013-03-13 +## [0.8.3] - 2013-03-13 * [Fix] inoitfy/kqueue memory leak [#36][] (reported by @nbkolchin) * [Fix] kqueue: use fsnFlags for watching a directory [#33][] (reported by @nbkolchin) -## v0.8.2 / 2013-02-07 +## [0.8.2] - 2013-02-07 * [Doc] add Authors * [Fix] fix data races for map access [#29][] (thanks @fsouza) -## v0.8.1 / 2013-01-09 +## [0.8.1] - 2013-01-09 * [Fix] Windows path separators * [Doc] BSD License -## v0.8.0 / 2012-11-09 +## [0.8.0] - 2012-11-09 * kqueue: directory watching improvements (thanks @vmirage) * inotify: add `IN_MOVED_TO` [#25][] (requested by @cpisto) * [Fix] kqueue: deleting watched directory [#24][] (reported by @jakerr) -## v0.7.4 / 2012-10-09 +## [0.7.4] - 2012-10-09 * [Fix] inotify: fixes from https://codereview.appspot.com/5418045/ (ugorji) * [Fix] kqueue: preserve watch flags when watching for delete [#21][] (reported by @robfig) * [Fix] kqueue: watch the directory even if it isn't a new watch (thanks @robfig) * [Fix] kqueue: modify after recreation of file -## v0.7.3 / 2012-09-27 +## [0.7.3] - 2012-09-27 * [Fix] kqueue: watch with an existing folder inside the watched folder (thanks @vmirage) * [Fix] kqueue: no longer get duplicate CREATE events -## v0.7.2 / 2012-09-01 +## [0.7.2] - 2012-09-01 * kqueue: events for created directories -## v0.7.1 / 2012-07-14 +## [0.7.1] - 2012-07-14 * [Fix] for renaming files -## v0.7.0 / 2012-07-02 +## [0.7.0] - 2012-07-02 * [Feature] FSNotify flags * [Fix] inotify: Added file name back to event path -## v0.6.0 / 2012-06-06 +## [0.6.0] - 2012-06-06 * kqueue: watch files after directory created (thanks @tmc) -## v0.5.1 / 2012-05-22 +## [0.5.1] - 2012-05-22 * [Fix] inotify: remove all watches before Close() -## v0.5.0 / 2012-05-03 +## [0.5.0] - 2012-05-03 * [API] kqueue: return errors during watch instead of sending over channel * kqueue: match symlink behavior on Linux @@ -284,22 +295,22 @@ kqueue: Fix logic for CREATE after REMOVE [#111](https://github.com/fsnotify/fsn * [Fix] kqueue: handle EINTR (reported by @robfig) * [Doc] Godoc example [#1][] (thanks @davecheney) -## v0.4.0 / 2012-03-30 +## [0.4.0] - 2012-03-30 * Go 1 released: build with go tool * [Feature] Windows support using winfsnotify * Windows does not have attribute change notifications * Roll attribute notifications into IsModify -## v0.3.0 / 2012-02-19 +## [0.3.0] - 2012-02-19 * kqueue: add files when watch directory -## v0.2.0 / 2011-12-30 +## [0.2.0] - 2011-12-30 * update to latest Go weekly code -## v0.1.0 / 2011-10-19 +## [0.1.0] - 2011-10-19 * kqueue: add watch on file creation to match inotify * kqueue: create file event diff --git a/go.mod b/go.mod index f37d2c03..54089e48 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,5 @@ module github.com/fsnotify/fsnotify go 1.13 require golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c + +retract v1.5.0 From 3eb7fa4b3213c056d4657a9776041e96e8fe73b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vernet?= Date: Thu, 7 May 2020 16:06:57 +0200 Subject: [PATCH 13/20] Removed dead link --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index df57b1b2..c3c30240 100644 --- a/README.md +++ b/README.md @@ -84,10 +84,6 @@ func main() { Please refer to [CONTRIBUTING][] before opening an issue or pull request. -## Example - -See [example_test.go](https://github.com/fsnotify/fsnotify/blob/master/example_test.go). - ## FAQ **When a file is moved to another directory is it still being watched?** From 0aba082a316ad65f61be188306f1aa48b4e5eb76 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Thu, 13 Jan 2022 20:02:46 -0700 Subject: [PATCH 14/20] Update issue templates (#410) * Update issue templates * remove old issue template --- .github/ISSUE_TEMPLATE.md | 11 -------- .github/ISSUE_TEMPLATE/bug_report.md | 33 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++++ 3 files changed, 53 insertions(+), 11 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 4ad1aed8..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,11 +0,0 @@ -Before reporting an issue, please ensure you are using the latest release of fsnotify. - -### Which operating system (GOOS) and version are you using? - -Linux: lsb_release -a -macOS: sw_vers -Windows: systeminfo | findstr /B /C:OS - -### Please describe the issue that occurred. - -### Are you able to reproduce the issue? Please provide steps to reproduce and a code sample if possible. diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..82a6a1c2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,33 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +Before reporting an issue, please ensure you are using the latest release of `fsnotify`, and please +search for existing issue to avoid duplicates. + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Which operating system and version are you using?** + +Linux: lsb_release -a +macOS: sw_vers +Windows: systeminfo | findstr /B /C:OS + +**Additional context** +If applicable, add screenshots or a code sample to help explain your problem. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..bbcbbe7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 83f9fe6d481bccd82236185ae073952ee52185e1 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Thu, 13 Jan 2022 20:49:28 -0700 Subject: [PATCH 15/20] Test on Go 1.18 and two most recent versions (#411) * Test on Go 1.18 and two most recent versions * on push * ci --- .github/workflows/test.yml | 19 ++++++++----------- go.mod | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a20673a0..8301cb9d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,5 @@ name: test -on: - push: - pull_request: - +on: [push] jobs: test: strategy: @@ -13,17 +10,15 @@ jobs: - macos-latest - windows-latest go: + - '1.18.0-beta1' - '1.17' - '1.16' - - '1.15' - - '1.14' - - '1.13' - - '1.12' runs-on: ${{ matrix.os }} steps: - name: setup Go uses: actions/setup-go@v2 with: + stable: 'false' go-version: ${{ matrix.go }} - name: checkout @@ -38,6 +33,8 @@ jobs: steps: - name: setup Go uses: actions/setup-go@v2 + with: + go-version: '1.17' - name: checkout uses: actions/checkout@v2 @@ -54,7 +51,7 @@ jobs: uses: golangci/golangci-lint-action@v2 continue-on-error: true with: - version: v1.41.1 - # this is here as a workaround for https://github.com/golangci/golangci-lint-action/issues/244 - skip-pkg-cache: true + version: latest + skip-go-installation: true + diff --git a/go.mod b/go.mod index 54089e48..8d1fc129 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/fsnotify/fsnotify -go 1.13 +go 1.16 require golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c From 6e1d4e4293d4dfe30968f1e0b24f44447216f7a5 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Thu, 13 Jan 2022 21:35:17 -0700 Subject: [PATCH 16/20] update readme --- README.md | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c3c30240..238306fe 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,8 @@ # File system notifications for Go -[![GoDoc](https://godoc.org/github.com/fsnotify/fsnotify?status.svg)](https://godoc.org/github.com/fsnotify/fsnotify) [![Go Report Card](https://goreportcard.com/badge/github.com/fsnotify/fsnotify)](https://goreportcard.com/report/github.com/fsnotify/fsnotify) +[![Go Reference](https://pkg.go.dev/badge/github.com/fsnotify/fsnotify.svg)](https://pkg.go.dev/github.com/fsnotify/fsnotify) [![Go Report Card](https://goreportcard.com/badge/github.com/fsnotify/fsnotify)](https://goreportcard.com/report/github.com/fsnotify/fsnotify) -fsnotify utilizes [golang.org/x/sys](https://godoc.org/golang.org/x/sys) rather than `syscall` from the standard library. Ensure you have the latest version installed by running: - -```console -go get -u golang.org/x/sys/... -``` +fsnotify utilizes [golang.org/x/sys](https://godoc.org/golang.org/x/sys) rather than `syscall` from the standard library. Cross platform: Windows, Linux, BSD and macOS. @@ -16,22 +12,20 @@ Cross platform: Windows, Linux, BSD and macOS. | kqueue | BSD, macOS, iOS\* | Supported | | ReadDirectoryChangesW | Windows | Supported | | FSEvents | macOS | [Planned](https://github.com/fsnotify/fsnotify/issues/11) | -| FEN | Solaris 11 | [In Progress](https://github.com/fsnotify/fsnotify/issues/12) | -| fanotify | Linux 2.6.37+ | [Planned](https://github.com/fsnotify/fsnotify/issues/114) | +| FEN | Solaris 11 | [In Progress](https://github.com/fsnotify/fsnotify/pull/371) | +| fanotify | Linux 2.6.37+ | [Maybe](https://github.com/fsnotify/fsnotify/issues/114) | | USN Journals | Windows | [Maybe](https://github.com/fsnotify/fsnotify/issues/53) | | Polling | *All* | [Maybe](https://github.com/fsnotify/fsnotify/issues/9) | \* Android and iOS are untested. -Please see [the documentation](https://godoc.org/github.com/fsnotify/fsnotify) and consult the [FAQ](#faq) for usage information. +Please see [the documentation](https://pkg.go.dev/github.com/fsnotify/fsnotify) and consult the [FAQ](#faq) for usage information. ## API stability -fsnotify is a fork of [howeyc/fsnotify](https://godoc.org/github.com/howeyc/fsnotify) with a new API as of v1.0. The API is based on [this design document](http://goo.gl/MrYxyA). - -All [releases](https://github.com/fsnotify/fsnotify/releases) are tagged based on [Semantic Versioning](http://semver.org/). Further API changes are [planned](https://github.com/fsnotify/fsnotify/milestones), and will be tagged with a new major revision number. +fsnotify is a fork of [howeyc/fsnotify](https://github.com/howeyc/fsnotify) with a new API as of v1.0. The API is based on [this design document](http://goo.gl/MrYxyA). -Go 1.6 supports dependencies located in the `vendor/` folder. Unless you are creating a library, it is recommended that you copy fsnotify into `vendor/github.com/fsnotify/fsnotify` within your project, and likewise for `golang.org/x/sys`. +All [releases](https://github.com/fsnotify/fsnotify/releases) are tagged based on [Semantic Versioning](http://semver.org/). ## Usage From d696f5c8ce33cfe43aa59f9608b363e2545878a6 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Thu, 13 Jan 2022 21:38:49 -0700 Subject: [PATCH 17/20] revise contributing --- CONTRIBUTING.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 828a60b2..8a642563 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,18 +48,6 @@ fsnotify uses build tags to compile different code on Linux, BSD, macOS, and Win Before doing a pull request, please do your best to test your changes on multiple platforms, and list which platforms you were able/unable to test on. -To aid in cross-platform testing there is a Vagrantfile for Linux and BSD. - -* Install [Vagrant](http://www.vagrantup.com/) and [VirtualBox](https://www.virtualbox.org/) -* Setup [Vagrant Gopher](https://github.com/nathany/vagrant-gopher) in your `src` folder. -* Run `vagrant up` from the project folder. You can also setup just one box with `vagrant up linux` or `vagrant up bsd` (note: the BSD box doesn't support Windows hosts at this time, and NFS may prompt for your host OS password) -* Once setup, you can run the test suite on a given OS with a single command `vagrant ssh linux -c 'cd fsnotify/fsnotify; go test'`. -* When you're done, you will want to halt or destroy the Vagrant boxes. - -Notice: fsnotify file system events won't trigger in shared folders. The tests get around this limitation by using the /tmp directory. - -Right now there is no equivalent solution for Windows and macOS, but there are Windows VMs [freely available from Microsoft](http://www.modern.ie/en-us/virtualization-tools#downloads). - ### Maintainers Help maintaining fsnotify is welcome. To be a maintainer: @@ -67,11 +55,6 @@ Help maintaining fsnotify is welcome. To be a maintainer: * Submit a pull request and sign the CLA as above. * You must be able to run the test suite on Mac, Windows, Linux and BSD. -To keep master clean, the fsnotify project uses the "apply mail" workflow outlined in Nathaniel Talbott's post ["Merge pull request" Considered Harmful][am]. This requires installing [hub][]. - All code changes should be internal pull requests. Releases are tagged using [Semantic Versioning](http://semver.org/). - -[hub]: https://github.com/github/hub -[am]: http://blog.spreedly.com/2014/06/24/merge-pull-request-considered-harmful/#.VGa5yZPF_Zs From 62a598a8847cd850def73ff9a90e1e15f327d8c8 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Thu, 13 Jan 2022 22:07:14 -0700 Subject: [PATCH 18/20] maintainers wanted --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 238306fe..c67b5eb9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # File system notifications for Go -[![Go Reference](https://pkg.go.dev/badge/github.com/fsnotify/fsnotify.svg)](https://pkg.go.dev/github.com/fsnotify/fsnotify) [![Go Report Card](https://goreportcard.com/badge/github.com/fsnotify/fsnotify)](https://goreportcard.com/report/github.com/fsnotify/fsnotify) +[![Go Reference](https://pkg.go.dev/badge/github.com/fsnotify/fsnotify.svg)](https://pkg.go.dev/github.com/fsnotify/fsnotify) [![Go Report Card](https://goreportcard.com/badge/github.com/fsnotify/fsnotify)](https://goreportcard.com/report/github.com/fsnotify/fsnotify) [![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg)](https://github.com/fsnotify/fsnotify/issues/183) + + fsnotify utilizes [golang.org/x/sys](https://godoc.org/golang.org/x/sys) rather than `syscall` from the standard library. From af855d7e6014ec848882bb2ed7d40d536872d275 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Fri, 14 Jan 2022 00:26:03 -0700 Subject: [PATCH 19/20] Final Notice: Maintainers Wanted --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c67b5eb9..7797745d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # File system notifications for Go -[![Go Reference](https://pkg.go.dev/badge/github.com/fsnotify/fsnotify.svg)](https://pkg.go.dev/github.com/fsnotify/fsnotify) [![Go Report Card](https://goreportcard.com/badge/github.com/fsnotify/fsnotify)](https://goreportcard.com/report/github.com/fsnotify/fsnotify) [![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg)](https://github.com/fsnotify/fsnotify/issues/183) +[![Go Reference](https://pkg.go.dev/badge/github.com/fsnotify/fsnotify.svg)](https://pkg.go.dev/github.com/fsnotify/fsnotify) [![Go Report Card](https://goreportcard.com/badge/github.com/fsnotify/fsnotify)](https://goreportcard.com/report/github.com/fsnotify/fsnotify) [![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg)](https://github.com/fsnotify/fsnotify/issues/413) From 73c3b57488289565a440dd578a30c7163861de81 Mon Sep 17 00:00:00 2001 From: Ichinose Shogo Date: Mon, 17 Jan 2022 23:35:07 +0900 Subject: [PATCH 20/20] fix go vet warnings: call to (*T).Fatalf from a non-test goroutine (#416) --- inotify_poller_test.go | 6 +++++- inotify_test.go | 9 +++++++-- integration_test.go | 18 +++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/inotify_poller_test.go b/inotify_poller_test.go index c7475454..110e00db 100644 --- a/inotify_poller_test.go +++ b/inotify_poller_test.go @@ -179,7 +179,7 @@ func TestPollerConcurrent(t *testing.T) { for { ok, err := poller.wait() if err != nil { - t.Fatalf("poller failed: %v", err) + t.Errorf("poller failed: %v", err) } oks <- ok if !<-live { @@ -227,4 +227,8 @@ func TestPollerConcurrent(t *testing.T) { t.Fatalf("expected true") } tfd.get(t) + + // wait for all goroutines for finish. + live <- false + <-oks } diff --git a/inotify_test.go b/inotify_test.go index 90c82b8e..f121c014 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -330,15 +330,17 @@ func TestInotifyInnerMapLength(t *testing.T) { if err != nil { t.Fatalf("Failed to create watcher: %v", err) } - defer w.Close() err = w.Add(testFile) if err != nil { t.Fatalf("Failed to add testFile: %v", err) } + var wg sync.WaitGroup + wg.Add(1) go func() { + defer wg.Done() for err := range w.Errors { - t.Fatalf("error received: %s", err) + t.Errorf("error received: %s", err) } }() @@ -357,6 +359,9 @@ func TestInotifyInnerMapLength(t *testing.T) { if len(w.paths) != 0 { t.Fatalf("Expected paths len is 0, but got: %d, %v", len(w.paths), w.paths) } + + w.Close() + wg.Wait() } func TestInotifyOverflow(t *testing.T) { diff --git a/integration_test.go b/integration_test.go index fc09e03f..85d7b9bb 100644 --- a/integration_test.go +++ b/integration_test.go @@ -14,6 +14,7 @@ import ( "path" "path/filepath" "runtime" + "sync" "sync/atomic" "testing" "time" @@ -75,9 +76,12 @@ func TestFsnotifyMultipleOperations(t *testing.T) { watcher := newWatcher(t) // Receive errors on the error channel on a separate goroutine + var wg sync.WaitGroup + wg.Add(1) go func() { + defer wg.Done() for err := range watcher.Errors { - t.Fatalf("error received: %s", err) + t.Errorf("error received: %s", err) } }() @@ -187,6 +191,9 @@ func TestFsnotifyMultipleOperations(t *testing.T) { case <-time.After(2 * time.Second): t.Fatal("event stream was not closed after 2 seconds") } + + // wait for all groutines to finish. + wg.Wait() } func TestFsnotifyMultipleCreates(t *testing.T) { @@ -837,10 +844,13 @@ func TestRemovalOfWatch(t *testing.T) { t.Fatalf("Could not remove the watch: %v\n", err) } + var wg sync.WaitGroup + wg.Add(1) go func() { + defer wg.Done() select { case ev := <-watcher.Events: - t.Fatalf("We received event: %v\n", ev) + t.Errorf("We received event: %v\n", ev) case <-time.After(500 * time.Millisecond): t.Log("No event received, as expected.") } @@ -858,7 +868,9 @@ func TestRemovalOfWatch(t *testing.T) { if err := os.Chmod(testFileAlreadyExists, 0700); err != nil { t.Fatalf("chmod failed: %s", err) } - time.Sleep(400 * time.Millisecond) + + // wait for all groutines to finish. + wg.Wait() } func TestFsnotifyAttrib(t *testing.T) {