Exemple #1
0
// Stop watching a path
func (man *Watchman) ForgetPath(path string) error {
	if _, ok := man.paths[path]; !ok {
		return nil
	}
	if len(path) > 1 && strings.HasSuffix(path, "/") {
		path = strings.TrimRight(path, "/")
	}
	m := router.Message{
		Event:    0x0,
		FileName: "-" + path,
	}
	err := man.client.Write(router.SYS_ID, m.String())
	if err != nil {
		return err
	}
	man.client.Unsubscribe(path)
	delete(man.paths, path)
	return nil
}
Exemple #2
0
// Add a file path to watch list, specify the events as you need
func (man *Watchman) WatchPath(path string, events uint32) error {
	if _, ok := man.paths[path]; ok {
		man.paths[path] = events
		return nil
	}
	if len(path) > 1 && strings.HasSuffix(path, "/") {
		path = strings.TrimRight(path, "/")
	}
	m := router.Message{
		Event:    0x0,
		FileName: "+" + path,
	}
	err := man.client.Write(router.SYS_ID, m.String())
	if err != nil {
		return err
	}
	man.client.Subscribe(path)
	man.paths[path] = events
	return nil
}
Exemple #3
0
// The event operation is:
//{
//    "Mask":0,
//    "Name":"FAIL:/path/to/file" or "Name":"SUCCESS:/path/to/file"
//}
func (em *Distributer) Eject(env *inotify.Event, t time.Time) {
	var m router.Message
	if env.Mask == 0x0 {
		m = router.Message{
			Event:    0x0,
			FileName: env.Name,
		}
	} else {
		m = router.Message{
			Event:    env.Mask,
			FileName: env.Name,
		}
		buildMsg(env.Name, &m)
	}
	to_list := pool.triggerPaths(env.Name)
	for _, to := range to_list {
		if em.passby(env, t) {
			em.Write(to, m.String())
		}
	}
}