Skip to content

Commit

Permalink
chore: switch to fsnotify for fs events
Browse files Browse the repository at this point in the history
  • Loading branch information
alejofernandez authored and cyx committed Apr 30, 2021
1 parent 112c1a3 commit c6bcb36
Show file tree
Hide file tree
Showing 43 changed files with 28 additions and 4,818 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/briandowns/spinner v1.12.0
github.com/charmbracelet/glamour v0.2.0
github.com/fatih/color v1.10.0 // indirect
github.com/fsnotify/fsnotify v1.4.7
github.com/getsentry/sentry-go v0.10.0
github.com/golang/mock v1.5.0
github.com/golang/snappy v0.0.3 // indirect
Expand All @@ -26,7 +27,6 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/pierrec/lz4/v4 v4.1.3 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rjeczalik/notify v0.9.2
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.0
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8=
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
Expand Down Expand Up @@ -603,7 +601,6 @@ golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
38 changes: 26 additions & 12 deletions internal/branding/branding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"net"
"net/http"
"path/filepath"
"text/template"
"time"

"github.com/auth0/auth0-cli/internal/open"
"github.com/fsnotify/fsnotify"
"github.com/guiguan/caster"
"github.com/rjeczalik/notify"
)

type Client struct {
Expand Down Expand Up @@ -119,27 +119,41 @@ func buildRoutes(ctx context.Context, requestTimeout time.Duration, templateData
func broadcastCustomTemplateChanges(ctx context.Context, filename string) *caster.Caster {
publisher := caster.New(ctx)

dir, file := filepath.Split(filename)
c := make(chan notify.EventInfo)
if err := notify.Watch(dir, c, notify.Write); err != nil {
return publisher
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}

go func() {
for eventInfo := range c {
if filepath.Base(eventInfo.Path()) == file {
publisher.Pub(true)
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
if event.Op&fsnotify.Write == fsnotify.Write {
publisher.Pub(true)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Fatal(err)
}
}
}()

// release resources when the file is closed or the input is cancelled
go func() {
<-ctx.Done()
notify.Stop(c)
close(c)
watcher.Close()
publisher.Close()
}()

err = watcher.Add(filename)
if err != nil {
log.Fatal(err)
}

return publisher
}

Expand Down
92 changes: 0 additions & 92 deletions vendor/github.com/rjeczalik/notify/.gitignore

This file was deleted.

31 changes: 0 additions & 31 deletions vendor/github.com/rjeczalik/notify/.travis.yml

This file was deleted.

10 changes: 0 additions & 10 deletions vendor/github.com/rjeczalik/notify/AUTHORS

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/rjeczalik/notify/LICENSE

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/github.com/rjeczalik/notify/README.md

This file was deleted.

27 changes: 0 additions & 27 deletions vendor/github.com/rjeczalik/notify/appveyor.yml

This file was deleted.

53 changes: 0 additions & 53 deletions vendor/github.com/rjeczalik/notify/debug.go

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/github.com/rjeczalik/notify/debug_debug.go

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/github.com/rjeczalik/notify/debug_nodebug.go

This file was deleted.

Loading

0 comments on commit c6bcb36

Please sign in to comment.