Skip to content

Commit

Permalink
allow to build without fsnotify
Browse files Browse the repository at this point in the history
  • Loading branch information
Itay Donanhirsh committed Mar 11, 2021
1 parent c66f7c6 commit 62afbb6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bin: clutter
.PHONY: clutter
clutter:
go build -o $(BINDIR)/clutter $(GO_BUILD_OPTS) ./cmd/clutter
go build -o $(BINDIR)/clutter-nofsnotify --tags nofsnotify $(GO_BUILD_OPTS) ./cmd/clutter

.PHONY: test
test: test-unit test-end-to-end
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ make install

See [releases](https://github.com/cluttercode/clutter/releases).


## TODO

- [ ] More tests.
Expand Down
5 changes: 2 additions & 3 deletions cmd/clutter/cmd_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"time"

"github.com/fsnotify/fsnotify"
cli "github.com/urfave/cli/v2"

"github.com/cluttercode/clutter/internal/pkg/index"
Expand Down Expand Up @@ -100,7 +99,7 @@ var (
return nil
}

watcher, err := fsnotify.NewWatcher()
watcher, err := fsnNewWatcher()
if err != nil {
return fmt.Errorf("watcher: %w", err)
}
Expand Down Expand Up @@ -153,7 +152,7 @@ var (
return

case event := <-watcher.Events:
if event.Op&(fsnotify.Write|fsnotify.Remove|fsnotify.Rename|fsnotify.Create) != 0 {
if event.Op&(fsnWrite|fsnRemove|fsnRename|fsnCreate) != 0 {
z.Infow("file modified", "event", event.Name)
done <- errRefresh
return
Expand Down
16 changes: 16 additions & 0 deletions cmd/clutter/fsnotify_real.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build !nofsnotify

package main

import (
"github.com/fsnotify/fsnotify"
)

var (
fsnCreate = fsnotify.Create
fsnWrite = fsnotify.Write
fsnRemove = fsnotify.Remove
fsnRename = fsnotify.Rename
)

var fsnNewWatcher = fsnotify.NewWatcher
31 changes: 31 additions & 0 deletions cmd/clutter/fsnotify_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// +build nofsnotify

package main

import "errors"

type Op uint32

const (
fsnCreate Op = iota
fsnWrite
fsnRemove
fsnRename
)

type Event struct {
Name string
Op Op
}

type Watcher struct {
Errors chan error
Events chan Event
}

func (w *Watcher) Add(name string) error { return nil }
func (w *Watcher) Close() error { return nil }

func fsnNewWatcher() (*Watcher, error) {
return nil, errors.New("fsnotify is not supported")
}

0 comments on commit 62afbb6

Please sign in to comment.