diff options
Diffstat (limited to 'src/inotify/inutil/inotify_util.go')
-rw-r--r-- | src/inotify/inutil/inotify_util.go | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/inotify/inutil/inotify_util.go b/src/inotify/inutil/inotify_util.go index 3a5eed5..c643e59 100644 --- a/src/inotify/inutil/inotify_util.go +++ b/src/inotify/inutil/inotify_util.go @@ -1,3 +1,20 @@ +// Copyright 2015 Luke Shumaker <lukeshu@sbcglobal.net>. +// +// This is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of +// the License, or (at your option) any later version. +// +// This software is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this manual; if not, see +// <http://www.gnu.org/licenses/>. + +// Package inutil provides a channel-based interface to inotify. package inutil import ( @@ -6,25 +23,21 @@ import ( "syscall" ) -const ( - // Flags for the parameter of InotifyInit1(). - // These, oddly, appear to be 24-bit numbers. - IN_CLOEXEC = inotify.IN_CLOEXEC -) - type Watcher struct { Events <-chan inotify.Event - events chan<- inotify.Event Errors <-chan error + events chan<- inotify.Event errors chan<- error in *inotify.Inotify } +// Wraps inotify.InotifyInit() func WatcherInit() (*Watcher, error) { in, err := inotify.InotifyInit() return newWatcher(in, err) } +// Wraps inotify.InotifyInit1() func WatcherInit1(flags int) (*Watcher, error) { in, err := inotify.InotifyInit1(flags &^ inotify.IN_NONBLOCK) return newWatcher(in, err) @@ -44,14 +57,19 @@ func newWatcher(in *inotify.Inotify, err error) (*Watcher, error) { return o, err } +// Wraps inotify.Inotify.AddWatch(); adds or modifies a watch. func (o *Watcher) AddWatch(path string, mask inotify.Mask) (inotify.Wd, error) { return o.in.AddWatch(path, mask) } +// Wraps inotify.Inotify.RmWatch(); removes a watch. func (o *Watcher) RmWatch(wd inotify.Wd) error { return o.in.RmWatch(wd) } +// Wraps inotify.Inotify.Close(). Unlike inotify.Inotify.Close(), +// this cannot block. Also unlike inotify.Inotify.Close(), nothing +// may be received from the channel after this is called. func (o *Watcher) Close() { func() { defer recover() |