示例#1
0
文件: alfred.go 项目: qjpcpu/watchman
func buildMsg(path string, msg *router.Message) {
	if fi, err := os.Stat(path); err == nil {
		msg.Size = fi.Size()
		if t, ok := fi.Sys().(*syscall.Stat_t); ok {
			msg.Inode = t.Ino
			msg.AccessTime = time.Unix(t.Atim.Unix()).Format(TimeFormat)
			msg.ChangeTime = time.Unix(t.Ctim.Unix()).Format(TimeFormat)
			msg.ModifyTime = time.Unix(t.Mtim.Unix()).Format(TimeFormat)
		} else {
			logging.Debug("Can't get %v details by syscall", path)
		}
	}
}
示例#2
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
}
示例#3
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
}
示例#4
0
文件: alfred.go 项目: qjpcpu/watchman
// 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())
		}
	}
}