Tweak vendoring to include rfsnotify which has recursive support via fsnotify

This commit is contained in:
KemoNine 2020-08-26 01:28:29 -04:00
parent 46be9f5794
commit 9f4a68c904
28 changed files with 264 additions and 127 deletions

4
go.mod
View File

@ -7,5 +7,7 @@ require (
github.com/d2r2/go-i2c v0.0.0-20191123181816-73a8a799d6bc github.com/d2r2/go-i2c v0.0.0-20191123181816-73a8a799d6bc
github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 github.com/dietsche/rfsnotify v0.0.0-20200716145600-b37be6e4177f
github.com/fsnotify/fsnotify v1.4.9 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
) )

4
go.sum
View File

@ -6,7 +6,11 @@ github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e h1:ZG3JBA6rPRl0xxQ+
github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e/go.mod h1:oA+9PUt8F1aKJ6o4YU1T120i7sgo1T6/1LWEEBy0BSs= github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e/go.mod h1:oA+9PUt8F1aKJ6o4YU1T120i7sgo1T6/1LWEEBy0BSs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dietsche/rfsnotify v0.0.0-20200716145600-b37be6e4177f h1:b3QvpXLSx1U13VM79rSkA+6Xv4lmT/urEMzA36Yma0U=
github.com/dietsche/rfsnotify v0.0.0-20200716145600-b37be6e4177f/go.mod h1:ztitxkMUaBsHRey1tS5xFCd4gm/zAQwA9yfCP5y4cAA=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0= 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-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=

24
vendor/github.com/dietsche/rfsnotify/.gitignore generated vendored Normal file
View File

@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof

22
vendor/github.com/dietsche/rfsnotify/LICENSE generated vendored Normal file
View File

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Gregory L. Dietsche
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

21
vendor/github.com/dietsche/rfsnotify/README.md generated vendored Normal file
View File

@ -0,0 +1,21 @@
# rfsnotify v0.1.0
recursive directory notifications built as a wrapper around fsnotify (golang)
[![GoDoc](https://godoc.org/github.com/dietsche/rfsnotify?status.svg)](https://godoc.org/github.com/dietsche/rfsnotify)
This is a thin wrapper around https://github.com/fsnotify/fsnotify instead of only monitoring a top level folder,
it allows you to monitor all folders underneath the folder you specify.
Example:
--------
(error handling omitted to improve readability)
```
import "github.com/dietsche/rfsnotify"
//rfsnotify works exactly like fsnotify and implements the same API.
watcher, err := rfsnotify.NewWatcher()
//rfsnotify adds two new API entry points:
watcher.AddRecursive("/tmp/")
watcher.RemoveRecursive("/tmp/")
```

133
vendor/github.com/dietsche/rfsnotify/rfsnotify.go generated vendored Normal file
View File

@ -0,0 +1,133 @@
// Package rfsnotify implements recursive folder monitoring by wrapping the excellent fsnotify library
package rfsnotify
import (
"gopkg.in/fsnotify.v1"
"errors"
"os"
"path/filepath"
)
// RWatcher wraps fsnotify.Watcher. When fsnotify adds recursive watches, you should be able to switch your code to use fsnotify.Watcher
type RWatcher struct {
Events chan fsnotify.Event
Errors chan error
done chan struct{}
fsnotify *fsnotify.Watcher
isClosed bool
}
// NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.
func NewWatcher() (*RWatcher, error) {
fsWatch, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
m := &RWatcher{}
m.fsnotify = fsWatch
m.Events = make(chan fsnotify.Event)
m.Errors = make(chan error)
m.done = make(chan struct{})
go m.start()
return m, nil
}
// Add starts watching the named file or directory (non-recursively).
func (m *RWatcher) Add(name string) error {
if m.isClosed {
return errors.New("rfsnotify instance already closed")
}
return m.fsnotify.Add(name)
}
// AddRecursive starts watching the named directory and all sub-directories.
func (m *RWatcher) AddRecursive(name string) error {
if m.isClosed {
return errors.New("rfsnotify instance already closed")
}
if err := m.watchRecursive(name, false); err != nil {
return err
}
return nil
}
// Remove stops watching the the named file or directory (non-recursively).
func (m *RWatcher) Remove(name string) error {
return m.fsnotify.Remove(name)
}
// RemoveRecursive stops watching the named directory and all sub-directories.
func (m *RWatcher) RemoveRecursive(name string) error {
if err := m.watchRecursive(name, true); err != nil {
return err
}
return nil
}
// Close removes all watches and closes the events channel.
func (m *RWatcher) Close() error {
if m.isClosed {
return nil
}
close(m.done)
m.isClosed = true
return nil
}
func (m *RWatcher) start() {
for {
select {
case e := <-m.fsnotify.Events:
s, err := os.Stat(e.Name)
if err == nil && s != nil && s.IsDir() {
if e.Op&fsnotify.Create != 0 {
m.watchRecursive(e.Name, false)
}
}
//Can't stat a deleted directory, so just pretend that it's always a directory and
//try to remove from the watch list... we really have no clue if it's a directory or not...
if e.Op&fsnotify.Remove != 0 {
m.fsnotify.Remove(e.Name)
}
m.Events <- e
case e := <-m.fsnotify.Errors:
m.Errors <- e
case <-m.done:
m.fsnotify.Close()
close(m.Events)
close(m.Errors)
return
}
}
}
// watchRecursive adds all directories under the given one to the watch list.
// this is probably a very racey process. What if a file is added to a folder before we get the watch added?
func (m *RWatcher) watchRecursive(path string, unWatch bool) error {
err := filepath.Walk(path, func(walkPath string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
if fi.IsDir() {
if unWatch {
if err = m.fsnotify.Remove(walkPath); err != nil {
return err
}
} else {
if err = m.fsnotify.Add(walkPath); err != nil {
return err
}
}
}
return nil
})
return err
}

View File

@ -1,12 +0,0 @@
root = true
[*.go]
indent_style = tab
indent_size = 4
insert_final_newline = true
[*.{yml,yaml}]
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

View File

@ -1 +0,0 @@
go.sum linguist-generated

View File

@ -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

View File

@ -1,5 +0,0 @@
module github.com/fsnotify/fsnotify
go 1.13
require golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9

View File

@ -1,2 +0,0 @@
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=

5
vendor/gopkg.in/fsnotify.v1/.editorconfig generated vendored Normal file
View File

@ -0,0 +1,5 @@
root = true
[*]
indent_style = tab
indent_size = 4

30
vendor/gopkg.in/fsnotify.v1/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,30 @@
sudo: false
language: go
go:
- 1.8.x
- 1.9.x
- tip
matrix:
allow_failures:
- go: tip
fast_finish: true
before_script:
- go get -u github.com/golang/lint/golint
script:
- go test -v --race ./...
after_script:
- test -z "$(gofmt -s -l -w . | tee /dev/stderr)"
- test -z "$(golint ./... | tee /dev/stderr)"
- go vet ./...
os:
- linux
- osx
notifications:
email: false

View File

@ -1,5 +1,5 @@
Copyright (c) 2012 The Go Authors. All rights reserved. Copyright (c) 2012 The Go Authors. All rights reserved.
Copyright (c) 2012-2019 fsnotify Authors. All rights reserved. Copyright (c) 2012 fsnotify Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are

View File

@ -10,16 +10,16 @@ go get -u golang.org/x/sys/...
Cross platform: Windows, Linux, BSD and macOS. Cross platform: Windows, Linux, BSD and macOS.
| Adapter | OS | Status | |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) | |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) | |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) | |ReadDirectoryChangesW|Windows|Supported [![Build status](https://ci.appveyor.com/api/projects/status/ivwjubaih4r0udeh/branch/master?svg=true)](https://ci.appveyor.com/project/NathanYoungman/fsnotify/branch/master)|
| FSEvents | macOS | [Planned](https://github.com/fsnotify/fsnotify/issues/11) | |FSEvents |macOS |[Planned](https://github.com/fsnotify/fsnotify/issues/11)|
| FEN | Solaris 11 | [In Progress](https://github.com/fsnotify/fsnotify/issues/12) | |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) | |fanotify |Linux 2.6.37+ | |
| USN Journals | Windows | [Maybe](https://github.com/fsnotify/fsnotify/issues/53) | |USN Journals |Windows |[Maybe](https://github.com/fsnotify/fsnotify/issues/53)|
| Polling | *All* | [Maybe](https://github.com/fsnotify/fsnotify/issues/9) | |Polling |*All* |[Maybe](https://github.com/fsnotify/fsnotify/issues/9)|
\* Android and iOS are untested. \* Android and iOS are untested.
@ -33,53 +33,6 @@ All [releases](https://github.com/fsnotify/fsnotify/releases) are tagged based o
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`. 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`.
## Usage
```go
package main
import (
"log"
"github.com/fsnotify/fsnotify"
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Println("error:", err)
}
}
}()
err = watcher.Add("/tmp/foo")
if err != nil {
log.Fatal(err)
}
<-done
}
```
## Contributing ## Contributing
Please refer to [CONTRIBUTING][] before opening an issue or pull request. Please refer to [CONTRIBUTING][] before opening an issue or pull request.
@ -112,10 +65,6 @@ There are OS-specific limits as to how many watches can be created:
* Linux: /proc/sys/fs/inotify/max_user_watches contains the limit, reaching this limit results in a "no space left on device" error. * Linux: /proc/sys/fs/inotify/max_user_watches contains the limit, reaching this limit results in a "no space left on device" error.
* BSD / OSX: sysctl variables "kern.maxfiles" and "kern.maxfilesperproc", reaching these limits results in a "too many open files" error. * BSD / OSX: sysctl variables "kern.maxfiles" and "kern.maxfilesperproc", reaching these limits results in a "too many open files" error.
**Why don't notifications work with NFS filesystems or filesystem in userspace (FUSE)?**
fsnotify requires support from underlying OS to work. The current NFS protocol does not provide network level support for file notifications.
[#62]: https://github.com/howeyc/fsnotify/issues/62 [#62]: https://github.com/howeyc/fsnotify/issues/62
[#18]: https://github.com/fsnotify/fsnotify/issues/18 [#18]: https://github.com/fsnotify/fsnotify/issues/18
[#11]: https://github.com/fsnotify/fsnotify/issues/11 [#11]: https://github.com/fsnotify/fsnotify/issues/11

View File

@ -63,6 +63,4 @@ func (e Event) String() string {
} }
// Common errors that can be reported by a watcher // Common errors that can be reported by a watcher
var ( var ErrEventOverflow = errors.New("fsnotify queue overflow")
ErrEventOverflow = errors.New("fsnotify queue overflow")
)

View File

@ -40,12 +40,12 @@ func newFdPoller(fd int) (*fdPoller, error) {
poller.fd = fd poller.fd = fd
// Create epoll fd // Create epoll fd
poller.epfd, errno = unix.EpollCreate1(unix.EPOLL_CLOEXEC) poller.epfd, errno = unix.EpollCreate1(0)
if poller.epfd == -1 { if poller.epfd == -1 {
return nil, errno return nil, errno
} }
// Create pipe; pipe[0] is the read end, pipe[1] the write end. // Create pipe; pipe[0] is the read end, pipe[1] the write end.
errno = unix.Pipe2(poller.pipe[:], unix.O_NONBLOCK|unix.O_CLOEXEC) errno = unix.Pipe2(poller.pipe[:], unix.O_NONBLOCK)
if errno != nil { if errno != nil {
return nil, errno return nil, errno
} }

View File

@ -8,4 +8,4 @@ package fsnotify
import "golang.org/x/sys/unix" import "golang.org/x/sys/unix"
const openMode = unix.O_NONBLOCK | unix.O_RDONLY | unix.O_CLOEXEC const openMode = unix.O_NONBLOCK | unix.O_RDONLY

View File

@ -9,4 +9,4 @@ package fsnotify
import "golang.org/x/sys/unix" import "golang.org/x/sys/unix"
// note: this constant is not defined on BSD // note: this constant is not defined on BSD
const openMode = unix.O_EVTONLY | unix.O_CLOEXEC const openMode = unix.O_EVTONLY

7
vendor/modules.txt vendored
View File

@ -10,8 +10,13 @@ github.com/d2r2/go-logger
# github.com/davecgh/go-spew v1.1.1 # github.com/davecgh/go-spew v1.1.1
## explicit ## explicit
github.com/davecgh/go-spew/spew github.com/davecgh/go-spew/spew
# github.com/dietsche/rfsnotify v0.0.0-20200716145600-b37be6e4177f
## explicit
github.com/dietsche/rfsnotify
# github.com/fsnotify/fsnotify v1.4.9 # github.com/fsnotify/fsnotify v1.4.9
## explicit ## explicit
github.com/fsnotify/fsnotify
# golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 # golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9
golang.org/x/sys/unix golang.org/x/sys/unix
# gopkg.in/fsnotify.v1 v1.4.7
## explicit
gopkg.in/fsnotify.v1