當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Watcher.RemoveWatch方法代碼示例

本文整理匯總了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
		}
	}
}
開發者ID:rliebling,項目名稱:reflex,代碼行數:26,代碼來源:workers.go

示例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)
	}
}
開發者ID:akavel,項目名稱:gomon,代碼行數:28,代碼來源:watcher.go

示例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:
		}
	}
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:22,代碼來源:launcher.go


注:本文中的github.com/howeyc/fsnotify.Watcher.RemoveWatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。