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


Golang Watcher.RemoveWatch方法代碼示例

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


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

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