From: Dan Fuhry Date: Tue, 12 Dec 2023 04:49:02 +0000 (-0500) Subject: various fixes and improvements X-Git-Tag: v1.7.2^0 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;ds=sidebyside;p=fsnotify.git various fixes and improvements - add RawOp field - support CLOSE events on inotify systems --- diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 88d4f93..f87a27e 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -37,5 +37,5 @@ body: validations: {"required": true} attributes: label: 'Did you try the latest main branch?' - description: 'Please try the latest main branch as well, with e.g.:
`go get github.com/fsnotify/fsnotify@main`' + description: 'Please try the latest main branch as well, with e.g.:
`go get gitlab.ha.xx0r.info/dan/fsnotify@main`' options: ['No', 'Yes'] diff --git a/backend_inotify.go b/backend_inotify.go index fe5033b..b4b0667 100644 --- a/backend_inotify.go +++ b/backend_inotify.go @@ -359,7 +359,8 @@ func (w *Watcher) AddWith(name string, opts ...addOpt) error { var flags uint32 = 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_CLOSE_WRITE | unix.IN_CLOSE_NOWRITE return w.watches.updatePath(name, func(existing *watch) (*watch, error) { if existing != nil { @@ -577,5 +578,9 @@ func (w *Watcher) newEvent(name string, mask uint32) Event { if mask&unix.IN_ATTRIB == unix.IN_ATTRIB { e.Op |= Chmod } + if mask&unix.IN_CLOSE_WRITE == unix.IN_CLOSE_WRITE || mask&unix.IN_CLOSE_NOWRITE == unix.IN_CLOSE_NOWRITE { + e.Op |= Close + } + e.RawOp = mask return e } diff --git a/cmd/fsnotify/dedup.go b/cmd/fsnotify/dedup.go index 67269d4..778e75a 100644 --- a/cmd/fsnotify/dedup.go +++ b/cmd/fsnotify/dedup.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/fsnotify/fsnotify" + "go.fuhry.dev/fsnotify" ) // Depending on the system, a single "write" can generate many Write events; for diff --git a/cmd/fsnotify/file.go b/cmd/fsnotify/file.go index 357e693..967c1e7 100644 --- a/cmd/fsnotify/file.go +++ b/cmd/fsnotify/file.go @@ -4,7 +4,7 @@ import ( "os" "path/filepath" - "github.com/fsnotify/fsnotify" + "go.fuhry.dev/fsnotify" ) // Watch one or more files, but instead of watching the file directly it watches diff --git a/cmd/fsnotify/main.go b/cmd/fsnotify/main.go index cdd9de7..31a6ff2 100644 --- a/cmd/fsnotify/main.go +++ b/cmd/fsnotify/main.go @@ -12,7 +12,7 @@ var usage = ` fsnotify is a Go library to provide cross-platform file system notifications. This command serves as an example and debugging tool. -https://github.com/fsnotify/fsnotify +https://go.fuhry.dev/fsnotify Commands: diff --git a/cmd/fsnotify/watch.go b/cmd/fsnotify/watch.go index 046a133..37b608d 100644 --- a/cmd/fsnotify/watch.go +++ b/cmd/fsnotify/watch.go @@ -1,6 +1,6 @@ package main -import "github.com/fsnotify/fsnotify" +import "go.fuhry.dev/fsnotify" // This is the most basic example: it prints events to the terminal as we // receive them. diff --git a/fsnotify.go b/fsnotify.go index c230d37..58cf561 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -30,6 +30,8 @@ type Event struct { // This is a bitmask and some systems may send multiple operations at once. // Use the Event.Has() method instead of comparing with ==. Op Op + + RawOp uint32 } // Op describes a set of file operations. @@ -60,6 +62,9 @@ const ( // get triggered very frequently by some software. For example, Spotlight // indexing on macOS, anti-virus software, backup software, etc. Chmod + + // File was closed. + Close ) // Common errors that can be reported. @@ -86,6 +91,9 @@ func (o Op) String() string { if o.Has(Chmod) { b.WriteString("|CHMOD") } + if o.Has(Close) { + b.WriteString("|CLOSE") + } if b.Len() == 0 { return "[no events]" } diff --git a/fsnotify_test.go b/fsnotify_test.go index 49124ad..859e2e6 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -16,7 +16,7 @@ import ( "testing" "time" - "github.com/fsnotify/fsnotify/internal" + "go.fuhry.dev/fsnotify/internal" ) // Set soft open file limit to the maximum; on e.g. OpenBSD it's 512/1024. @@ -1349,16 +1349,18 @@ func TestEventString(t *testing.T) { want string }{ {Event{}, `[no events] ""`}, - {Event{"/file", 0}, `[no events] "/file"`}, + {Event{"/file", 0, 0}, `[no events] "/file"`}, - {Event{"/file", Chmod | Create}, + {Event{"/file", Chmod | Create, 0}, `CREATE|CHMOD "/file"`}, - {Event{"/file", Rename}, + {Event{"/file", Rename, 0}, `RENAME "/file"`}, - {Event{"/file", Remove}, + {Event{"/file", Remove, 0}, `REMOVE "/file"`}, - {Event{"/file", Write | Chmod}, + {Event{"/file", Write | Chmod, 0}, `WRITE|CHMOD "/file"`}, + {Event{"/file", Write | Close, 0}, + `WRITE|CLOSE "/file"`}, } for _, tt := range tests { diff --git a/go.mod b/go.mod index 1deb88c..6e13713 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/fsnotify/fsnotify +module go.fuhry.dev/fsnotify go 1.17 diff --git a/helpers_test.go b/helpers_test.go index 2051a94..8ca46a4 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/fsnotify/fsnotify/internal" + "go.fuhry.dev/fsnotify/internal" ) type testCase struct {