github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/worker/filenotifywatcher/watcher_linux.go (about)

     1  //go:build linux
     2  // +build linux
     3  
     4  // Copyright 2023 Canonical Ltd.
     5  // Licensed under the AGPLv3, see LICENCE file for details.
     6  
     7  package filenotifywatcher
     8  
     9  import "k8s.io/utils/inotify"
    10  
    11  type watcher struct {
    12  	watcher *inotify.Watcher
    13  }
    14  
    15  func newWatcher() (INotifyWatcher, error) {
    16  	w, err := inotify.NewWatcher()
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  	return &watcher{
    21  		watcher: w,
    22  	}, nil
    23  }
    24  
    25  func (w *watcher) Watch(path string) error {
    26  	return w.watcher.Watch(path)
    27  }
    28  
    29  func (w *watcher) Events() <-chan *inotify.Event {
    30  	return w.watcher.Event
    31  }
    32  
    33  func (w *watcher) Errors() <-chan error {
    34  	return w.watcher.Error
    35  }
    36  
    37  func (w *watcher) Close() error {
    38  	return w.watcher.Close()
    39  }