Skip to content

Commit

Permalink
Merge pull request #77 from DrOctavius/main
Browse files Browse the repository at this point in the history
fixes
DrOctavius authored Oct 17, 2023

Verified

This commit was signed with the committer’s verified signature.
ViBiOh Vincent Boutour
2 parents befb26f + 9d6ef9e commit aad2a5c
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 9 additions & 2 deletions core/helpers/filesystem/fsnotify/notify.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ type WatchCallback func(e EventData)

// This is the structure when we send the configuration to the watcher!
type WatchConfig struct {
CallbackGoRoutine bool
// This is the callback which should be called!
Callback WatchCallback
// What operations should listen on!
@@ -194,12 +195,18 @@ func (n *Notifier) Start() *Notifier {

//log.Println("aaa", event.Op, Op(event.Op))

watchConfig.Callback(EventData{
ev := EventData{
Path: event.Name,
Time: time.Now(),
Name: filepath.Base(event.Name), // Filter the file Name!
Op: Op(event.Op),
})
}

if watchConfig.CallbackGoRoutine {
go watchConfig.Callback(ev)
} else {
watchConfig.Callback(ev)
}
}

/*log.Println("event:", event)
17 changes: 9 additions & 8 deletions core/listeners/websocket/server/inotify/notifier.go
Original file line number Diff line number Diff line change
@@ -23,13 +23,13 @@ type ListeningPath struct {
type OnNotificationRead func(h *server.Hub, data interface{}, plainData string)

type WSNotifier struct {
WebSocketServer *server.Server
ListeningPaths []ListeningPath
WSHub *server.Hub
DelayRead time.Duration

OnNotificationRead OnNotificationRead
OnError func(msg string)
WebSocketServer *server.Server
ListeningPaths []ListeningPath
WSHub *server.Hub
DelayRead time.Duration
OnNotificationReadGoRoutine bool
OnNotificationRead OnNotificationRead
OnError func(msg string)
}

func (wsNotifier *WSNotifier) onError(msg string) {
@@ -83,9 +83,10 @@ func New(wsNotifier *WSNotifier) *WSNotifier {

// Add to watcher!
fsNotifier.Watch(listeningPath.Path, fsnotify.WatchConfig{
CallbackGoRoutine: wsNotifier.OnNotificationReadGoRoutine,
Callback: func(e fsnotify.EventData) {

if wsNotifier.DelayRead != 0 {
if wsNotifier.DelayRead > 0 {
time.Sleep(wsNotifier.DelayRead)
}

0 comments on commit aad2a5c

Please sign in to comment.