This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new e72e85cf0 chore(deps): fsnotify instead of radovskyb/watcher
e72e85cf0 is described below

commit e72e85cf0ccd8e6a98e7d9d37dc1ac8081bbcbee
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Mon Jun 5 15:31:13 2023 +0200

    chore(deps): fsnotify instead of radovskyb/watcher
    
    Ref #4326
---
 go.mod                |  3 +--
 go.sum                |  2 --
 pkg/util/sync/file.go | 27 +++++++++++++--------------
 3 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/go.mod b/go.mod
index 2de261de3..ae87e876c 100644
--- a/go.mod
+++ b/go.mod
@@ -9,6 +9,7 @@ require (
        github.com/apache/camel-k/v2/pkg/kamelet/repository v0.0.0
        github.com/container-tools/spectrum v0.6.19
        github.com/evanphx/json-patch v5.6.0+incompatible
+       github.com/fsnotify/fsnotify v1.6.0
        github.com/gertd/go-pluralize v0.2.1
        github.com/go-logr/logr v1.2.4
        github.com/google/go-containerregistry v0.15.2
@@ -26,7 +27,6 @@ require (
        github.com/prometheus/client_golang v1.15.1
        github.com/prometheus/client_model v0.4.0
        github.com/prometheus/common v0.44.0
-       github.com/radovskyb/watcher v1.0.7
        github.com/redhat-developer/service-binding-operator v1.3.4
        github.com/rs/xid v1.5.0
        github.com/scylladb/go-set v1.0.2
@@ -90,7 +90,6 @@ require (
        github.com/docker/docker-credential-helpers v0.7.0 // indirect
        github.com/emicklei/go-restful/v3 v3.9.0 // indirect
        github.com/evanphx/json-patch/v5 v5.6.0 // indirect
-       github.com/fsnotify/fsnotify v1.6.0 // indirect
        github.com/go-kit/log v0.2.1 // indirect
        github.com/go-logfmt/logfmt v0.5.1 // indirect
        github.com/go-logr/zapr v1.2.3 // indirect
diff --git a/go.sum b/go.sum
index b2e0bc17e..e7846c52a 100644
--- a/go.sum
+++ b/go.sum
@@ -608,8 +608,6 @@ github.com/prometheus/procfs v0.9.0/go.mod 
h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB
 github.com/prometheus/statsd_exporter v0.21.0 
h1:hA05Q5RFeIjgwKIYEdFd59xu5Wwaznf33yKI+pyX6T8=
 github.com/prometheus/statsd_exporter v0.21.0/go.mod 
h1:rbT83sZq2V+p73lHhPZfMc3MLCHmSHelCh9hSGYNLTQ=
 github.com/prometheus/tsdb v0.7.1/go.mod 
h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
-github.com/radovskyb/watcher v1.0.7 
h1:AYePLih6dpmS32vlHfhCeli8127LzkIgwJGcwwe8tUE=
-github.com/radovskyb/watcher v1.0.7/go.mod 
h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg=
 github.com/redhat-developer/service-binding-operator v1.3.4 
h1:ApCkGtXSKWCrRBQZCo/wRJ+XZWLe1EOnPjYtGcYSSMQ=
 github.com/redhat-developer/service-binding-operator v1.3.4/go.mod 
h1:mS/deuQ5m8rMnY9NbJ+0eTB0sC7Oy8SibiRnuyD++Bc=
 github.com/rickb777/date v1.13.0 
h1:+8AmwLuY1d/rldzdqvqTEg7107bZ8clW37x4nsdG3Hs=
diff --git a/pkg/util/sync/file.go b/pkg/util/sync/file.go
index bddfed798..bb9aee226 100644
--- a/pkg/util/sync/file.go
+++ b/pkg/util/sync/file.go
@@ -20,38 +20,37 @@ package sync
 
 import (
        "context"
-       "time"
 
-       "github.com/apache/camel-k/v2/pkg/util/log"
-       "github.com/radovskyb/watcher"
+       "github.com/fsnotify/fsnotify"
 )
 
 // File returns a channel that signals each time the content of the file 
changes.
 func File(ctx context.Context, path string) (<-chan bool, error) {
-       w := watcher.New()
-       if err := w.Add(path); err != nil {
+       watcher, err := fsnotify.NewWatcher()
+       if err != nil {
                return nil, err
        }
-       w.FilterOps(watcher.Write)
 
        out := make(chan bool)
+
+       // Start listening for events.
        go func() {
                for {
                        select {
                        case <-ctx.Done():
                                return
-                       case <-w.Event:
-                               out <- true
+                       case event := <-watcher.Events:
+                               if event.Has(fsnotify.Write) {
+                                       out <- true
+                               }
                        }
                }
        }()
 
-       go func() {
-               if err := w.Start(200 * time.Millisecond); err != nil {
-                       log.Error(err, "Error while starting watcher")
-                       close(out)
-               }
-       }()
+       err = watcher.Add(path)
+       if err != nil {
+               return nil, err
+       }
 
        return out, nil
 }

Reply via email to