From 89d89edfbbb9a7a573f5a425d4d5f6ea244e58e7 Mon Sep 17 00:00:00 2001 From: leecha <22087646+leecha@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:54:27 +0800 Subject: [PATCH] Update the addOpt function to be public. --- backend_fen.go | 2 +- backend_inotify.go | 4 ++-- backend_kqueue.go | 2 +- backend_other.go | 2 +- backend_windows.go | 2 +- fsnotify.go | 28 ++++++++++++++-------------- helpers_test.go | 10 +++++----- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/backend_fen.go b/backend_fen.go index c349c326..bf0ad872 100644 --- a/backend_fen.go +++ b/backend_fen.go @@ -100,7 +100,7 @@ func (w *fen) Close() error { func (w *fen) Add(name string) error { return w.AddWith(name) } -func (w *fen) AddWith(name string, opts ...addOpt) error { +func (w *fen) AddWith(name string, opts ...AddOpt) error { if w.isClosed() { return ErrClosed } diff --git a/backend_inotify.go b/backend_inotify.go index 36c31169..86a4634b 100644 --- a/backend_inotify.go +++ b/backend_inotify.go @@ -252,7 +252,7 @@ func (w *inotify) Close() error { func (w *inotify) Add(name string) error { return w.AddWith(name) } -func (w *inotify) AddWith(path string, opts ...addOpt) error { +func (w *inotify) AddWith(path string, opts ...AddOpt) error { if w.isClosed() { return ErrClosed } @@ -296,7 +296,7 @@ func (w *inotify) AddWith(path string, opts ...addOpt) error { return w.add(path, with, false) } -func (w *inotify) add(path string, with withOpts, recurse bool) error { +func (w *inotify) add(path string, with WithOpts, recurse bool) error { var flags uint32 if with.noFollow { flags |= unix.IN_DONT_FOLLOW diff --git a/backend_kqueue.go b/backend_kqueue.go index d8de5ab7..89a3583e 100644 --- a/backend_kqueue.go +++ b/backend_kqueue.go @@ -292,7 +292,7 @@ func (w *kqueue) Close() error { func (w *kqueue) Add(name string) error { return w.AddWith(name) } -func (w *kqueue) AddWith(name string, opts ...addOpt) error { +func (w *kqueue) AddWith(name string, opts ...AddOpt) error { if debug { fmt.Fprintf(os.Stderr, "FSNOTIFY_DEBUG: %s AddWith(%q)\n", time.Now().Format("15:04:05.000000000"), name) diff --git a/backend_other.go b/backend_other.go index 5eb5dbc6..9362bd9c 100644 --- a/backend_other.go +++ b/backend_other.go @@ -18,6 +18,6 @@ func newBufferedBackend(sz uint, ev chan Event, errs chan error) (backend, error func (w *other) Close() error { return nil } func (w *other) WatchList() []string { return nil } func (w *other) Add(name string) error { return nil } -func (w *other) AddWith(name string, opts ...addOpt) error { return nil } +func (w *other) AddWith(name string, opts ...AddOpt) error { return nil } func (w *other) Remove(name string) error { return nil } func (w *other) xSupports(op Op) bool { return false } diff --git a/backend_windows.go b/backend_windows.go index c54a6308..8ab98fe5 100644 --- a/backend_windows.go +++ b/backend_windows.go @@ -110,7 +110,7 @@ func (w *readDirChangesW) Close() error { func (w *readDirChangesW) Add(name string) error { return w.AddWith(name) } -func (w *readDirChangesW) AddWith(name string, opts ...addOpt) error { +func (w *readDirChangesW) AddWith(name string, opts ...AddOpt) error { if w.isClosed() { return ErrClosed } diff --git a/fsnotify.go b/fsnotify.go index 61f94896..c51836df 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -319,7 +319,7 @@ func (w *Watcher) Add(path string) error { return w.b.Add(path) } // // - [WithBufferSize] sets the buffer size for the Windows backend; no-op on // other platforms. The default is 64K (65536 bytes). -func (w *Watcher) AddWith(path string, opts ...addOpt) error { return w.b.AddWith(path, opts...) } +func (w *Watcher) AddWith(path string, opts ...AddOpt) error { return w.b.AddWith(path, opts...) } // Remove stops monitoring the path for changes. // @@ -398,14 +398,14 @@ func (e Event) String() string { type ( backend interface { Add(string) error - AddWith(string, ...addOpt) error + AddWith(string, ...AddOpt) error Remove(string) error WatchList() []string Close() error xSupports(Op) bool } - addOpt func(opt *withOpts) - withOpts struct { + AddOpt func(opt *WithOpts) + WithOpts struct { bufsize int op Op noFollow bool @@ -420,12 +420,12 @@ var debug = func() bool { return os.Getenv("FSNOTIFY_DEBUG") == "1" }() -var defaultOpts = withOpts{ +var defaultOpts = WithOpts{ bufsize: 65536, // 64K op: Create | Write | Remove | Rename | Chmod, } -func getOptions(opts ...addOpt) withOpts { +func getOptions(opts ...AddOpt) WithOpts { with := defaultOpts for _, o := range opts { if o != nil { @@ -445,8 +445,8 @@ func getOptions(opts ...addOpt) withOpts { // you're hitting "queue or buffer overflow" errors ([ErrEventOverflow]). // // [ReadDirectoryChangesW]: https://learn.microsoft.com/en-gb/windows/win32/api/winbase/nf-winbase-readdirectorychangesw -func WithBufferSize(bytes int) addOpt { - return func(opt *withOpts) { opt.bufsize = bytes } +func WithBufferSize(bytes int) AddOpt { + return func(opt *WithOpts) { opt.bufsize = bytes } } // WithOps sets which operations to listen for. The default is [Create], @@ -463,19 +463,19 @@ func WithBufferSize(bytes int) addOpt { // // AddWith returns an error when using an unportable operation that's not // supported. Use [Watcher.Support] to check for support. -func withOps(op Op) addOpt { - return func(opt *withOpts) { opt.op = op } +func WithOps(op Op) AddOpt { + return func(opt *WithOpts) { opt.op = op } } // WithNoFollow disables following symlinks, so the symlinks themselves are // watched. -func withNoFollow() addOpt { - return func(opt *withOpts) { opt.noFollow = true } +func WithNoFollow() AddOpt { + return func(opt *WithOpts) { opt.noFollow = true } } // "Internal" option for recursive watches on inotify. -func withCreate() addOpt { - return func(opt *withOpts) { opt.sendCreate = true } +func WithCreate() AddOpt { + return func(opt *WithOpts) { opt.sendCreate = true } } var enableRecurse = true diff --git a/helpers_test.go b/helpers_test.go index 8ad80455..8ea23cb6 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -658,7 +658,7 @@ func supportsFilter(t *testing.T) { case "linux": // Run test. default: - t.Skip("withOps() not yet supported on " + runtime.GOOS) + t.Skip("WithOps() not yet supported on " + runtime.GOOS) } } @@ -676,7 +676,7 @@ func supportsNofollow(t *testing.T) { case "linux": // Run test. default: - t.Skip("withNoFollow() not yet supported on " + runtime.GOOS) + t.Skip("WithNoFollow() not yet supported on " + runtime.GOOS) } } @@ -866,11 +866,11 @@ loop: continue } - var follow addOpt + var follow AddOpt for i := range c.args { if c.args[i] == "nofollow" || c.args[i] == "no-follow" { c.args = append(c.args[:i], c.args[i+1:]...) - follow = withNoFollow() + follow = WithNoFollow() break } } @@ -904,7 +904,7 @@ loop: } do = append(do, func() { p := tmppath(tmp, c.args[0]) - err := w.w.AddWith(p, withOps(op), follow) + err := w.w.AddWith(p, WithOps(op), follow) if err != nil { t.Fatalf("line %d: addWatch(%q): %s", c.line+1, p, err) }