summaryrefslogtreecommitdiff
path: root/pkg/hooks/monitor.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-07-27 12:02:25 -0400
committerGitHub <noreply@github.com>2022-07-27 12:02:25 -0400
commit87f892e5b56c2fab2f394f8cc79794ccce03f510 (patch)
tree1ba831a9dddfb6927698bcb9e0c2bee913ad0dcb /pkg/hooks/monitor.go
parentc57b5c9b831695f8c54d11b4f288d6037c096fea (diff)
parent983cfb90e68d7b292b0f6ee8800c3f23383493cc (diff)
downloadpodman-87f892e5b56c2fab2f394f8cc79794ccce03f510.tar.gz
podman-87f892e5b56c2fab2f394f8cc79794ccce03f510.tar.bz2
podman-87f892e5b56c2fab2f394f8cc79794ccce03f510.zip
Merge pull request #15076 from mheon/bump_420_rc2
Bump to v4.2.0-RC2
Diffstat (limited to 'pkg/hooks/monitor.go')
-rw-r--r--pkg/hooks/monitor.go66
1 files changed, 0 insertions, 66 deletions
diff --git a/pkg/hooks/monitor.go b/pkg/hooks/monitor.go
deleted file mode 100644
index d2d7140a5..000000000
--- a/pkg/hooks/monitor.go
+++ /dev/null
@@ -1,66 +0,0 @@
-package hooks
-
-import (
- "context"
-
- current "github.com/containers/podman/v4/pkg/hooks/1.0.0"
- "github.com/fsnotify/fsnotify"
- "github.com/sirupsen/logrus"
-)
-
-// Monitor dynamically monitors hook directories for additions,
-// updates, and removals.
-//
-// This function writes two empty structs to the sync channel: the
-// first is written after the watchers are established and the second
-// when this function exits. The expected usage is:
-//
-// ctx, cancel := context.WithCancel(context.Background())
-// sync := make(chan error, 2)
-// go m.Monitor(ctx, sync)
-// err := <-sync // block until writers are established
-// if err != nil {
-// return err // failed to establish watchers
-// }
-// // do stuff
-// cancel()
-// err = <-sync // block until monitor finishes
-func (m *Manager) Monitor(ctx context.Context, sync chan<- error) {
- watcher, err := fsnotify.NewWatcher()
- if err != nil {
- sync <- err
- return
- }
- defer watcher.Close()
-
- for _, dir := range m.directories {
- err = watcher.Add(dir)
- if err != nil {
- logrus.Errorf("Failed to watch %q for hooks", dir)
- sync <- err
- return
- }
- logrus.Debugf("monitoring %q for hooks", dir)
- }
-
- sync <- nil
-
- for {
- select {
- case event := <-watcher.Events:
- m.hooks = make(map[string]*current.Hook)
- for _, dir := range m.directories {
- err = ReadDir(dir, m.extensionStages, m.hooks)
- if err != nil {
- logrus.Errorf("Failed loading hooks for %s: %v", event.Name, err)
- }
- }
- case <-ctx.Done():
- err = ctx.Err()
- logrus.Debugf("hook monitoring canceled: %v", err)
- sync <- err
- close(sync)
- return
- }
- }
-}