Skip to content

Commit

Permalink
Merge branch 'main' into configOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Jul 12, 2023
2 parents 90ac4bb + c35de00 commit 8fda0c5
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
# iOS
ios:
macos:
xcode: 12.5.1
xcode: 13.4.1
working_directory: ~/repo
steps:
- checkout
Expand Down
41 changes: 41 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: 'Bug report'
description: 'Create a bug report'
labels: ['bug']

body:
- type: 'textarea'
validations: {"required": true}
attributes:
label: 'Describe the bug'
placeholder: 'A clear and concise description of what the bug is: expected behaviour, observed behaviour, etc.'

- type: 'textarea'
validations: {"required": true}
attributes:
label: 'To Reproduce'
placeholder: 'Please provide the FULL code to reproduce the problem (something that can be copy/pasted and run without having to write additional code) and any additional steps that are needed.'

- type: 'textarea'
validations: {"required": true}
attributes:
label: 'Which operating system and version are you using?'
description: |
```
Linux: lsb_release -a
macOS: sw_vers
Windows: systeminfo | findstr /B /C:OS
BSD: uname -a
```
- type: 'input'
validations: {"required": true}
attributes:
label: 'Which fsnotify version are you using?'

- type: 'dropdown'
validations: {"required": true}
attributes:
label: 'Did you try the latest main branch?'
description: 'Please try the latest main branch as well, with e.g.:<br>`go get github.com/fsnotify/fsnotify@main`'
options: ['No', 'Yes']
33 changes: 0 additions & 33 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

20 changes: 0 additions & 20 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/other.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: 'Other'
about: "Anything that's not a bug such as feature requests, questions, etc."
title: ''
labels: ''
assignees: ''

---

10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.16', '1.19']
go: ['1.17', '1.20']
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3

- name: setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: checkout
uses: actions/checkout@v3

- name: build
run: |
for a in $(go tool dist list); do
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ jobs:
- ubuntu-latest
- windows-latest
go:
- '1.16'
- '1.19'
- '1.17'
- '1.20'
runs-on: ${{ matrix.os }}
steps:
- name: checkout
uses: actions/checkout@v3

- name: setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: checkout
uses: actions/checkout@v3

- name: test
run: |
go test -race ./...
Expand All @@ -46,7 +46,7 @@ jobs:
# Test only the latest Go version on macOS; we use the macOS builders for BSD
# and illumos, and GitHub doesn't allow many of them to run concurrently. If
# it works on Windows and Linux with Go 1.16, then it probably does on macOS
# it works on Windows and Linux with Go 1.17, then it probably does on macOS
# too.
testMacOS:
name: test
Expand All @@ -57,17 +57,17 @@ jobs:
- macos-11
- macos-12
go:
- '1.19'
- '1.20'
runs-on: ${{ matrix.os }}
steps:
- name: checkout
uses: actions/checkout@v3

- name: setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: checkout
uses: actions/checkout@v3

- name: test
run: |
go test -race ./...
Expand Down Expand Up @@ -96,25 +96,25 @@ jobs:
# NetBSD
testNetBSD:
runs-on: macos-12
name: test (netbsd, 1.18)
name: test (netbsd, 1.20)
steps:
- uses: actions/checkout@v3
- name: test (netbsd, 1.18)
- name: test (netbsd, 1.20)
id: test
uses: vmactions/netbsd-vm@v0
with:
prepare: pkg_add go
# TODO: no -race for the same reason as OpenBSD (the timing; it does run).
run: |
useradd -mG wheel action
su action -c 'go118 test ./...'
su action -c 'go120 test ./...'
# illumos
testillumos:
runs-on: macos-12
name: test (illumos, 1.19)
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: test (illumos, 1.19)
id: test
uses: papertigers/illumos-vm@r38
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
${{ runner.os }}-vagrant-
- name: setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: '1.19'

Expand Down
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Unreleased
----------
This version of fsnotify needs Go 1.17.

### Additions

Expand Down Expand Up @@ -38,9 +39,17 @@ Unreleased
Before it would merely return "short read", making it hard to detect this
error.

- all: return `ErrClosed` on `Add()` when the watcher is closed ([#516])
- kqueue: make sure events for all files are delivered properly when removing a
watched directory ([#526])

- kqueue: deal with `rm -rf watched-dir` better ([#526], [#537])
Previously they would get sent with "" or "." as the path name.

- kqueue: don't emit spurious Create events for symbolic links ([#524])

The link would get resolved but kqueue would "forget" it already saw the link
itself, resulting on a Create for every Write event for the directory.

- all: return ErrClosed on Add() when the watcher is closed ([#516])

- other: add `Watcher.Errors` and `Watcher.Events` to the no-op `Watcher` in
`backend_other.go`, making it easier to use on unsupported platforms such as
Expand Down
44 changes: 22 additions & 22 deletions backend_kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,10 @@ func (w *Watcher) WatchList() []string {
// Watch all events (except NOTE_EXTEND, NOTE_LINK, NOTE_REVOKE)
const noteAllEvents = unix.NOTE_DELETE | unix.NOTE_WRITE | unix.NOTE_ATTRIB | unix.NOTE_RENAME

// addWatch adds name to the watched file set.
// The flags are interpreted as described in kevent(2).
// Returns the real path to the file which was added, if any, which may be different from the one passed in the case of symlinks.
// addWatch adds name to the watched file set; the flags are interpreted as
// described in kevent(2).
//
// Returns the real path to the file which was added, with symlinks resolved.
func (w *Watcher) addWatch(name string, flags uint32) (string, error) {
var isDir bool
name = filepath.Clean(name)
Expand Down Expand Up @@ -442,35 +443,38 @@ func (w *Watcher) addWatch(name string, flags uint32) (string, error) {
return "", nil
}

// Follow Symlinks
//
// Linux can add unresolvable symlinks to the watch list without issue,
// and Windows can't do symlinks period. To maintain consistency, we
// will act like everything is fine if the link can't be resolved.
// There will simply be no file events for broken symlinks. Hence the
// returns of nil on errors.
// Follow Symlinks.
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
name, err = filepath.EvalSymlinks(name)
link, err := os.Readlink(name)
if err != nil {
// Return nil because Linux can add unresolvable symlinks to the
// watch list without problems, so maintain consistency with
// that. There will be no file events for broken symlinks.
// TODO: more specific check; returns os.PathError; ENOENT?
return "", nil
}

w.mu.Lock()
_, alreadyWatching = w.watches[name]
_, alreadyWatching = w.watches[link]
w.mu.Unlock()

if alreadyWatching {
return name, nil
// Add to watches so we don't get spurious Create events later
// on when we diff the directories.
w.watches[name] = 0
w.fileExists[name] = struct{}{}
return link, nil
}

name = link
fi, err = os.Lstat(name)
if err != nil {
return "", nil
}
}

// Retry on EINTR; open() can return EINTR in practice on macOS.
// See #354, and go issues 11180 and 39237.
// See #354, and Go issues 11180 and 39237.
for {
watchfd, err = unix.Open(name, openMode, 0)
if err == nil {
Expand Down Expand Up @@ -503,14 +507,13 @@ func (w *Watcher) addWatch(name string, flags uint32) (string, error) {
w.watchesByDir[parentName] = watchesByDir
}
watchesByDir[watchfd] = struct{}{}

w.paths[watchfd] = pathInfo{name: name, isDir: isDir}
w.mu.Unlock()
}

if isDir {
// Watch the directory if it has not been watched before,
// or if it was watched before, but perhaps only a NOTE_DELETE (watchDirectoryFiles)
// Watch the directory if it has not been watched before, or if it was
// watched before, but perhaps only a NOTE_DELETE (watchDirectoryFiles)
w.mu.Lock()

watchDir := (flags&unix.NOTE_WRITE) == unix.NOTE_WRITE &&
Expand All @@ -532,13 +535,10 @@ func (w *Watcher) addWatch(name string, flags uint32) (string, error) {
// Event values that it sends down the Events channel.
func (w *Watcher) readEvents() {
defer func() {
err := unix.Close(w.kq)
if err != nil {
w.Errors <- err
}
unix.Close(w.closepipe[0])
close(w.Events)
close(w.Errors)
_ = unix.Close(w.kq)
unix.Close(w.closepipe[0])
}()

eventBuffer := make([]unix.Kevent_t, 10)
Expand Down
17 changes: 17 additions & 0 deletions backend_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,20 @@ func TestRemoveState(t *testing.T) {
}
check(0)
}

func TestWindowsRemWatch(t *testing.T) {
tmp := t.TempDir()

touch(t, tmp, "file")

w := newWatcher(t)
defer w.Close()

addWatch(t, w, tmp)
if err := w.Remove(tmp); err != nil {
t.Fatalf("Could not remove the watch: %v\n", err)
}
if err := w.remWatch(tmp); err == nil {
t.Fatal("Should be fail with closed handle\n")
}
}
2 changes: 1 addition & 1 deletion fsnotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const (

// Common errors that can be reported.
var (
ErrNonExistentWatch = errors.New("fsnotify: can't remove non-existent watcher")
ErrNonExistentWatch = errors.New("fsnotify: can't remove non-existent watch")
ErrEventOverflow = errors.New("fsnotify: queue or buffer overflow")
ErrClosed = errors.New("fsnotify: watcher already closed")
)
Expand Down

0 comments on commit 8fda0c5

Please sign in to comment.