Skip to content

Commit 62afbb6

Browse files
author
Itay Donanhirsh
committed
allow to build without fsnotify
1 parent c66f7c6 commit 62afbb6

5 files changed

Lines changed: 50 additions & 4 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ bin: clutter
2525
.PHONY: clutter
2626
clutter:
2727
go build -o $(BINDIR)/clutter $(GO_BUILD_OPTS) ./cmd/clutter
28+
go build -o $(BINDIR)/clutter-nofsnotify --tags nofsnotify $(GO_BUILD_OPTS) ./cmd/clutter
2829

2930
.PHONY: test
3031
test: test-unit test-end-to-end

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ make install
237237

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

240-
241240
## TODO
242241

243242
- [ ] More tests.

cmd/clutter/cmd_index.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"path/filepath"
77
"time"
88

9-
"github.com/fsnotify/fsnotify"
109
cli "github.com/urfave/cli/v2"
1110

1211
"github.com/cluttercode/clutter/internal/pkg/index"
@@ -100,7 +99,7 @@ var (
10099
return nil
101100
}
102101

103-
watcher, err := fsnotify.NewWatcher()
102+
watcher, err := fsnNewWatcher()
104103
if err != nil {
105104
return fmt.Errorf("watcher: %w", err)
106105
}
@@ -153,7 +152,7 @@ var (
153152
return
154153

155154
case event := <-watcher.Events:
156-
if event.Op&(fsnotify.Write|fsnotify.Remove|fsnotify.Rename|fsnotify.Create) != 0 {
155+
if event.Op&(fsnWrite|fsnRemove|fsnRename|fsnCreate) != 0 {
157156
z.Infow("file modified", "event", event.Name)
158157
done <- errRefresh
159158
return

cmd/clutter/fsnotify_real.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// +build !nofsnotify
2+
3+
package main
4+
5+
import (
6+
"github.com/fsnotify/fsnotify"
7+
)
8+
9+
var (
10+
fsnCreate = fsnotify.Create
11+
fsnWrite = fsnotify.Write
12+
fsnRemove = fsnotify.Remove
13+
fsnRename = fsnotify.Rename
14+
)
15+
16+
var fsnNewWatcher = fsnotify.NewWatcher

cmd/clutter/fsnotify_stub.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// +build nofsnotify
2+
3+
package main
4+
5+
import "errors"
6+
7+
type Op uint32
8+
9+
const (
10+
fsnCreate Op = iota
11+
fsnWrite
12+
fsnRemove
13+
fsnRename
14+
)
15+
16+
type Event struct {
17+
Name string
18+
Op Op
19+
}
20+
21+
type Watcher struct {
22+
Errors chan error
23+
Events chan Event
24+
}
25+
26+
func (w *Watcher) Add(name string) error { return nil }
27+
func (w *Watcher) Close() error { return nil }
28+
29+
func fsnNewWatcher() (*Watcher, error) {
30+
return nil, errors.New("fsnotify is not supported")
31+
}

0 commit comments

Comments
 (0)