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


Golang inotify.Watcher類代碼示例

本文整理匯總了Golang中code/google/com/p/go/exp/inotify.Watcher的典型用法代碼示例。如果您正苦於以下問題:Golang Watcher類的具體用法?Golang Watcher怎麽用?Golang Watcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Watcher類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: FST_parse_watch

func FST_parse_watch(fst *FStree, dirname string, watcher *inotify.Watcher) {
	err := watcher.Watch(dirname)
	if err != nil {
		log.Fatal(err)
	}
	for child, _ := range fst.Tree[dirname].Children {
		spaces(fst.Tree[dirname].Depth)
		if fst.Tree[child].IsDir {
			fmt.Println(child, ":", fst.Tree[child].ModTime)
			FST_parse_watch(fst, child, watcher)
		} else {
			fmt.Println(fst.Tree[child].Name, "size:", fst.Tree[child].Size, "mod:", fst.Tree[child].ModTime)
		}
	}
}
開發者ID:jnhnum1,項目名稱:fss,代碼行數:15,代碼來源:dft_fetch_watch.go

示例2: FST_set_watch

//This function sets watch on folders in directory
func (tnt *TnTServer) FST_set_watch(dirname string, watcher *inotify.Watcher) {

	new_dirname := strings.TrimSuffix(dirname, "/")

	err := watcher.Watch(new_dirname)
	if err != nil {
		log.Fatal(err)
	}
	//fmt.Println(dirname)
	for name, fi := range tnt.Tree.MyTree {
		if fi.IsDir == true && name != "./" {
			new_name := strings.TrimPrefix(strings.TrimSuffix(name, "/"), "./")

			//fmt.Println("in fst_set_watch",dirname, name, tnt.root+new_name)
			err := watcher.Watch(tnt.root + new_name)
			if err != nil {
				log.Fatal(err)
			}
		}
	}
}
開發者ID:jnhnum1,項目名稱:fss,代碼行數:22,代碼來源:watcher.go

示例3: EventHandler

func EventHandler(watcher *inotify.Watcher) {
	// TODO: make into a slice to cache multiple cookies
	var moveFromEvent *inotify.Event

	for {
		select {
		case event := <-watcher.Event:
			switch {
			default:
				fmt.Println(event, time.Now())

			case event.Mask == DIR_CREATE:
				// This checks if a newly created directory has children.
				// If it does it adds them to the watch
				// This is to deal with the 'mdkir -p' problem
				paths := CollectPaths([]string{event.Name})
				if len(paths) > 1 {
					for i := 0; i < len(paths); i++ {
						watcher.Watch(paths[i])
					}
				} else {
					watcher.Watch(event.Name)
				}
				fmt.Println(event.String(), time.Now())

			case event.Mask == FILE_CREATE:
				// Create encryption key, put into keymanager
				// Upload as if a modify event
				fmt.Println(event.String(), time.Now())

			case event.Mask == FILE_MODIFY:
				// Encrypt && upload
				fmt.Println(event.String(), time.Now())

			case event.Mask == DIR_DELETE:
				// Signal server for a delete
				watcher.RemoveWatch(event.Name)
				fmt.Println(event.String(), time.Now())

			case event.Mask == FILE_DELETE:
				// Signal server for a delete, if has children, delete them as well.
				// This would present a case where the parent is deleted first and the
				// child delete events come after.
				fmt.Println(event.String(), time.Now())

			case event.Mask == DIR_MOVE_FROM:
				// When a dir is moved this will trigger possibly a lot more move events if there are lots of children
				// This is another reason for the cookie cache, anytime a move event happens, append the cookie.
				// Don't make it a static size.
				moveFromEvent = event
				watcher.RemoveWatch(event.Name)
				fmt.Println(event.String(), time.Now())

			case event.Mask == DIR_MOVE_TO:
				if event.Cookie == moveFromEvent.Cookie {
					watcher.Watch(event.Name)
					fmt.Println("\t", event.String(), time.Now())
				}

			case event.Mask == FILE_MOVE_FROM:
				// Check stored cookie from last move event, if it is the same, follow through with the move.
				// TODO: make this a cookie cache since we can have multiple storage Roots, this could cause misses of move events
				moveFromEvent = event
				fmt.Println(event.String(), time.Now())

			case event.Mask == FILE_MOVE_TO:
				if event.Cookie == moveFromEvent.Cookie {
					fmt.Println("\t", event.String(), time.Now())
				}
			}

		case err := <-watcher.Error:
			fmt.Println("WATCHER ERROR: ", err)
		}
	}
}
開發者ID:postfix,項目名稱:secureBox,代碼行數:76,代碼來源:eventHandler_linux.go


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