-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from arexon/fsnotify-dir-watcher
Switch to fsnotify for watch mode
- Loading branch information
Showing
10 changed files
with
177 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,26 @@ | ||
cloud.google.com/go/compute/metadata,https://github.com/googleapis/google-cloud-go/blob/compute/v1.5.0/compute/LICENSE,Apache-2.0 | ||
cloud.google.com/go/iam,https://github.com/googleapis/google-cloud-go/blob/iam/v0.3.0/iam/LICENSE,Apache-2.0 | ||
cloud.google.com/go/internal,https://github.com/googleapis/google-cloud-go/blob/v0.100.2/LICENSE,Apache-2.0 | ||
cloud.google.com/go/storage,https://github.com/googleapis/google-cloud-go/blob/storage/v1.21.0/storage/LICENSE,Apache-2.0 | ||
github.com/Bedrock-OSS/go-burrito/burrito,https://github.com/Bedrock-OSS/go-burrito/blob/v1.0.3/LICENSE,MIT | ||
github.com/Bedrock-OSS/regolith,https://github.com/Bedrock-OSS/regolith/blob/HEAD/LICENSE,MIT | ||
github.com/alessio/shellescape,https://github.com/alessio/shellescape/blob/v1.4.1/LICENSE,MIT | ||
github.com/antlr/antlr4/runtime/Go/antlr/v4,https://github.com/antlr/antlr4/blob/76fa05c21b12/runtime/Go/antlr/v4/LICENSE,BSD-3-Clause | ||
github.com/aws/aws-sdk-go,https://github.com/aws/aws-sdk-go/blob/v1.43.25/LICENSE.txt,Apache-2.0 | ||
github.com/aws/aws-sdk-go/internal/sync/singleflight,https://github.com/aws/aws-sdk-go/blob/v1.43.25/internal/sync/singleflight/LICENSE,BSD-3-Clause | ||
github.com/bgentry/go-netrc/netrc,https://github.com/bgentry/go-netrc/blob/9fd32a8b3d3d/LICENSE,MIT | ||
github.com/arexon/fsnotify,https://github.com/arexon/fsnotify/blob/1ebdc44d4bc2/LICENSE,BSD-3-Clause | ||
github.com/fatih/color,https://github.com/fatih/color/blob/v1.14.1/LICENSE.md,MIT | ||
github.com/gammazero/deque,https://github.com/gammazero/deque/blob/v0.2.1/LICENSE,MIT | ||
github.com/golang/groupcache/lru,https://github.com/golang/groupcache/blob/41bb18bfe9da/LICENSE,Apache-2.0 | ||
github.com/golang/protobuf,https://github.com/golang/protobuf/blob/v1.5.2/LICENSE,BSD-3-Clause | ||
github.com/google/go-cmp/cmp,https://github.com/google/go-cmp/blob/v0.5.8/LICENSE,BSD-3-Clause | ||
github.com/google/go-github/v39/github,https://github.com/google/go-github/blob/v39.2.0/LICENSE,BSD-3-Clause | ||
github.com/google/go-querystring/query,https://github.com/google/go-querystring/blob/v1.1.0/LICENSE,BSD-3-Clause | ||
github.com/googleapis/gax-go/v2,https://github.com/googleapis/gax-go/blob/v2.2.0/v2/LICENSE,BSD-3-Clause | ||
github.com/hashicorp/go-cleanhttp,https://github.com/hashicorp/go-cleanhttp/blob/v0.5.2/LICENSE,MPL-2.0 | ||
github.com/hashicorp/go-getter,https://github.com/arikkfir/go-getter/blob/281b7670b734/LICENSE,MPL-2.0 | ||
github.com/hashicorp/go-safetemp,https://github.com/hashicorp/go-safetemp/blob/v1.0.0/LICENSE,MPL-2.0 | ||
github.com/hashicorp/go-version,https://github.com/hashicorp/go-version/blob/v1.4.0/LICENSE,MPL-2.0 | ||
github.com/jmespath/go-jmespath,https://github.com/jmespath/go-jmespath/blob/v0.4.0/LICENSE,Apache-2.0 | ||
github.com/klauspost/compress,https://github.com/klauspost/compress/blob/v1.15.1/LICENSE,Apache-2.0 | ||
github.com/klauspost/compress/internal/snapref,https://github.com/klauspost/compress/blob/v1.15.1/internal/snapref/LICENSE,BSD-3-Clause | ||
github.com/klauspost/compress/zstd/internal/xxhash,https://github.com/klauspost/compress/blob/v1.15.1/zstd/internal/xxhash/LICENSE.txt,MIT | ||
github.com/mattn/go-colorable,https://github.com/mattn/go-colorable/blob/v0.1.13/LICENSE,MIT | ||
github.com/mattn/go-isatty,https://github.com/mattn/go-isatty/blob/v0.0.17/LICENSE,MIT | ||
github.com/mitchellh/go-homedir,https://github.com/mitchellh/go-homedir/blob/v1.1.0/LICENSE,MIT | ||
github.com/mitchellh/go-testing-interface,https://github.com/mitchellh/go-testing-interface/blob/v1.14.1/LICENSE,MIT | ||
github.com/muhammadmuzzammil1998/jsonc,https://github.com/muhammadmuzzammil1998/jsonc/blob/v1.0.0/LICENSE,MIT | ||
github.com/nightlyone/lockfile,https://github.com/nightlyone/lockfile/blob/v1.0.0/LICENSE,MIT | ||
github.com/otiai10/copy,https://github.com/otiai10/copy/blob/v1.7.0/LICENSE,MIT | ||
github.com/paul-mannino/go-fuzzywuzzy,https://github.com/paul-mannino/go-fuzzywuzzy/blob/54652b135d0e/LICENSE,GPL-3.0 | ||
github.com/spf13/cobra,https://github.com/spf13/cobra/blob/v1.6.1/LICENSE.txt,Apache-2.0 | ||
github.com/spf13/pflag,https://github.com/spf13/pflag/blob/v1.0.5/LICENSE,BSD-3-Clause | ||
github.com/stirante/go-simple-eval,https://github.com/stirante/go-simple-eval/blob/9ed520afbec1/LICENSE,GPL-3.0 | ||
github.com/ulikunitz/xz,https://github.com/ulikunitz/xz/blob/v0.5.10/LICENSE,BSD-3-Clause | ||
go.opencensus.io,https://github.com/census-instrumentation/opencensus-go/blob/v0.23.0/LICENSE,Apache-2.0 | ||
go.uber.org/atomic,https://github.com/uber-go/atomic/blob/v1.9.0/LICENSE.txt,MIT | ||
go.uber.org/multierr,https://github.com/uber-go/multierr/blob/v1.8.0/LICENSE.txt,MIT | ||
go.uber.org/zap,https://github.com/uber-go/zap/blob/v1.23.0/LICENSE.txt,MIT | ||
golang.org/x/crypto,https://cs.opensource.google/go/x/crypto/+/v0.1.0:LICENSE,BSD-3-Clause | ||
golang.org/x/exp,https://cs.opensource.google/go/x/exp/+/aae9b4e6:LICENSE,BSD-3-Clause | ||
golang.org/x/mod/semver,https://cs.opensource.google/go/x/mod/+/v0.6.0:LICENSE,BSD-3-Clause | ||
golang.org/x/net,https://cs.opensource.google/go/x/net/+/v0.1.0:LICENSE,BSD-3-Clause | ||
golang.org/x/oauth2,https://cs.opensource.google/go/x/oauth2/+/6242fa91:LICENSE,BSD-3-Clause | ||
golang.org/x/sys/unix,https://cs.opensource.google/go/x/sys/+/v0.4.0:LICENSE,BSD-3-Clause | ||
golang.org/x/sys/unix,https://cs.opensource.google/go/x/sys/+/v0.13.0:LICENSE,BSD-3-Clause | ||
golang.org/x/text,https://cs.opensource.google/go/x/text/+/v0.6.0:LICENSE,BSD-3-Clause | ||
golang.org/x/xerrors,https://cs.opensource.google/go/x/xerrors/+/5ec99f83:LICENSE,BSD-3-Clause | ||
google.golang.org/api,https://github.com/googleapis/google-api-go-client/blob/v0.73.0/LICENSE,BSD-3-Clause | ||
google.golang.org/api/internal/third_party/uritemplates,https://github.com/googleapis/google-api-go-client/blob/v0.73.0/internal/third_party/uritemplates/LICENSE,BSD-3-Clause | ||
google.golang.org/genproto/googleapis,https://github.com/googleapis/go-genproto/blob/acbaeb5b85eb/LICENSE,Apache-2.0 | ||
google.golang.org/grpc,https://github.com/grpc/grpc-go/blob/v1.45.0/LICENSE,Apache-2.0 | ||
google.golang.org/protobuf,https://github.com/protocolbuffers/protobuf-go/blob/v1.28.0/LICENSE,BSD-3-Clause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,99 +53,6 @@ func copyFileSecurityInfo(source string, target string) error { | |
return nil | ||
} | ||
|
||
// DirWatcher is a struct that provides easy to use methods for watching a | ||
// directory for changes. It uses FindFirstChangeNotification instead of | ||
// ReadDirectoryChanges, so it doesn't provide any information about the | ||
// changes, only the fact that something changed. | ||
// | ||
// Useful links: | ||
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstchangenotificationa | ||
// | ||
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findnextchangenotification | ||
// | ||
// https://pkg.go.dev/golang.org/x/[email protected]/windows | ||
// | ||
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-readdirectorychangesw | ||
type DirWatcher struct { | ||
handle windows.Handle | ||
} | ||
|
||
// NewDirWatcher creates a new DirWatcher for the given path. It filters out | ||
// some of the less interesting events like FILE_NOTIFY_CHANGE_LAST_ACCESS. | ||
func NewDirWatcher(path string) (*DirWatcher, error) { | ||
var notifyFilter uint32 = (windows.FILE_NOTIFY_CHANGE_FILE_NAME | | ||
windows.FILE_NOTIFY_CHANGE_DIR_NAME | | ||
// windows.FILE_NOTIFY_CHANGE_ATTRIBUTES | | ||
// windows.FILE_NOTIFY_CHANGE_SIZE | | ||
windows.FILE_NOTIFY_CHANGE_LAST_WRITE | | ||
// windows.FILE_NOTIFY_CHANGE_LAST_ACCESS | | ||
// windows.FILE_NOTIFY_CHANGE_SECURITY | | ||
windows.FILE_NOTIFY_CHANGE_CREATION) | ||
handle, err := windows.FindFirstChangeNotification( | ||
path, true, notifyFilter) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &DirWatcher{handle: handle}, nil | ||
} | ||
|
||
// WaitForChange locks the goroutine until a single change is detected. Note | ||
// that some changes are reported multiple times, for example saving a file | ||
// will cause a change to the file and a change to the directory. If you want | ||
// to report cases like that as one event, see WaitForChangeGroup. | ||
func (d *DirWatcher) WaitForChange() error { | ||
_, err := windows.WaitForSingleObject(d.handle, windows.INFINITE) | ||
if err != nil { | ||
return err | ||
} | ||
err = windows.FindNextChangeNotification(d.handle) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// WaitForChangeGroup locks a goroutine until it receives a change notification. | ||
// When that happens it sends the interruptionMessage to the | ||
// interruptionChannel. | ||
// Then it continues locking as long as other changes keep coming with | ||
// intervals less than the given timeout, to group notifications that come | ||
// in short intervals together. | ||
func (d *DirWatcher) WaitForChangeGroup( | ||
groupTimeout uint32, interruptionChannel chan string, | ||
interruptionMessage string, | ||
) error { | ||
err := d.WaitForChange() | ||
if err != nil { | ||
return err | ||
} | ||
// Instantly report the change | ||
interruptionChannel <- interruptionMessage | ||
// Consume all changes for groupDelay duration | ||
for { | ||
event, err := windows.WaitForSingleObject(d.handle, groupTimeout) | ||
if err != nil { | ||
return err | ||
} | ||
// Possible options: WAIT_OBJECT_0, WAIT_ABANDONED, WAIT_TIMEOUT, | ||
// WAIT_FAILED | ||
if event == uint32(windows.WAIT_TIMEOUT) || | ||
event == uint32(windows.WAIT_ABANDONED) { | ||
break | ||
} | ||
err = windows.FindNextChangeNotification(d.handle) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// Close closes DirWatcher handle. | ||
func (d *DirWatcher) Close() error { | ||
return windows.CloseHandle(d.handle) | ||
} | ||
|
||
// FindStandardMojangDir returns path to the com.mojang folder in the standard | ||
// Minecraft build. | ||
func FindStandardMojangDir() (string, error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.