@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/fsnotify/fsnotify"
14
14
"github.com/pkg/errors"
15
+
15
16
"go.jetpack.io/devbox/internal/cloud/envir"
16
17
)
17
18
@@ -44,40 +45,42 @@ func ListenToChanges(ctx context.Context, opts *ListenerOpts) error {
44
45
}()
45
46
46
47
// Start listening for events.
47
- go func () {
48
- for {
49
- select {
50
- case event , ok := <- watcher .Events :
51
- if ! ok {
52
- return
53
- }
48
+ go listenToEvents (watcher , opts )
54
49
55
- // mutagen sync changes show up as create events
56
- if event .Has (fsnotify .Write ) || event .Has (fsnotify .Create ) {
57
- status , err := readServiceStatus (event .Name )
58
- if err != nil {
59
- fmt .Fprintf (opts .Writer , "Error reading status file: %s\n " , err )
60
- continue
61
- }
50
+ // We only want events for the specific host.
51
+ return errors .WithStack (watcher .Add (filepath .Join (cloudFilePath (opts .ProjectDir ), opts .HostID )))
52
+ }
62
53
63
- status , saveChanges := opts .UpdateFunc (status )
64
- if saveChanges {
65
- if err := writeServiceStatusFile (event .Name , status ); err != nil {
66
- fmt .Fprintf (opts .Writer , "Error updating status file: %s\n " , err )
67
- }
68
- }
54
+ func listenToEvents (watcher * fsnotify.Watcher , opts * ListenerOpts ) {
55
+ for {
56
+ select {
57
+ case event , ok := <- watcher .Events :
58
+ if ! ok {
59
+ return
60
+ }
61
+
62
+ // mutagen sync changes show up as create events
63
+ if event .Has (fsnotify .Write ) || event .Has (fsnotify .Create ) {
64
+ status , err := readServiceStatus (event .Name )
65
+ if err != nil {
66
+ fmt .Fprintf (opts .Writer , "Error reading status file: %s\n " , err )
67
+ continue
69
68
}
70
- case err , ok := <- watcher .Errors :
71
- if ! ok {
72
- return
69
+
70
+ status , saveChanges := opts .UpdateFunc (status )
71
+ if saveChanges {
72
+ if err := writeServiceStatusFile (event .Name , status ); err != nil {
73
+ fmt .Fprintf (opts .Writer , "Error updating status file: %s\n " , err )
74
+ }
73
75
}
74
- fmt .Fprintf (opts .Writer , "error: %s\n " , err )
75
76
}
77
+ case err , ok := <- watcher .Errors :
78
+ if ! ok {
79
+ return
80
+ }
81
+ fmt .Fprintf (opts .Writer , "error: %s\n " , err )
76
82
}
77
- }()
78
-
79
- // We only want events for the specific host.
80
- return errors .WithStack (watcher .Add (filepath .Join (cloudFilePath (opts .ProjectDir ), opts .HostID )))
83
+ }
81
84
}
82
85
83
86
func cloudFilePath (projectDir string ) string {
0 commit comments