本文整理匯總了Golang中github.com/howeyc/fsnotify.Watcher.RemoveWatch方法的典型用法代碼示例。如果您正苦於以下問題:Golang Watcher.RemoveWatch方法的具體用法?Golang Watcher.RemoveWatch怎麽用?Golang Watcher.RemoveWatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/howeyc/fsnotify.Watcher
的用法示例。
在下文中一共展示了Watcher.RemoveWatch方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: watch
func watch(root string, watcher *fsnotify.Watcher, names chan<- string, done chan<- error) {
if err := filepath.Walk(root, walker(watcher)); err != nil {
// TODO: handle this somehow?
infoPrintf(-1, "Error while walking path %s: %s\n", root, err)
}
for {
select {
case e := <-watcher.Event:
path := strings.TrimPrefix(e.Name, "./")
names <- path
if e.IsCreate() {
if err := filepath.Walk(path, walker(watcher)); err != nil {
// TODO: handle this somehow?
infoPrintf(-1, "Error while walking path %s: %s\n", path, err)
}
}
if e.IsDelete() {
watcher.RemoveWatch(path)
}
case err := <-watcher.Error:
done <- err
return
}
}
}
示例2: processSubdir
func processSubdir(watcher *fsnotify.Watcher, ev *fsnotify.FileEvent) {
if ev.IsModify() {
return
}
if ev.IsDelete() {
log.Println("remove watch", ev.Name)
// FIXME: what to do with err?
watcher.RemoveWatch(ev.Name)
return
}
// FIXME: Lstat or Stat?
// TODO: what to do with err? can we safely ignore?
mode, err := os.Lstat(ev.Name)
if err != nil {
log.Println("error processing subdir:", err.Error())
return
}
if !mode.IsDir() {
return
}
// FIXME: handle renames
if ev.IsCreate() {
log.Println("add watch", ev.Name)
// FIXME: what to do with err?
watcher.Watch(ev.Name)
}
}
示例3: eventHandler
func (self *Launcher) eventHandler(watcher *fsnotify.Watcher) {
var info = map[string]ItemChangedStatus{}
for {
select {
case ev := <-watcher.Event:
name := path.Clean(ev.Name)
basename := path.Base(name)
if basename == "kde4" {
if ev.IsCreate() {
watcher.Watch(name)
} else if ev.IsDelete() {
watcher.RemoveWatch(name)
}
}
matched, _ := path.Match(`[^#.]*.desktop`, basename)
if matched {
go self.itemChangedHandler(ev, name, info)
}
case <-watcher.Error:
}
}
}