Beispiel #1
0
func (this *Watcher) handlecb(v *triggered, ev *fsnotify.FileEvent) {

	if !v.canrun() {
		return
	}
	defer v.setLastUpdate()

	// in windows some events are sent 3 times
	c := time.Tick(g_cooldown)
	<-c

	var t EvType
	// execute
	if ev.IsModify() {
		t = C_Modify
	} else if ev.IsCreate() {
		t = C_Create
	} else if ev.IsDelete() {
		t = C_Delete
	} else if ev.IsRename() {
		t = C_Rename
	} else if ev.IsAttrib() {
		t = C_Attrib
	} else {
		fmt.Fprintln(os.Stderr, "unknown event")
		return
	}

	this.cb(&WatchEvent{
		Type:  t,
		Fpath: ev.Name,
	})

}
Beispiel #2
0
func (self *Launcher) itemChangedHandler(ev *fsnotify.FileEvent, name string, info map[string]ItemChangedStatus) {
	if _, ok := info[name]; !ok {
		info[name] = ItemChangedStatus{
			make(chan bool),
			make(chan bool),
			make(chan bool),
			make(chan bool),
			0,
		}
	}
	if ev.IsRename() {
		logger.Info("renamed")
		select {
		case <-info[name].renamed:
		default:
		}
		go func() {
			select {
			case <-info[name].notRenamed:
				return
			case <-time.After(time.Second):
				<-info[name].renamed
				if true {
					self.emitItemChanged(name, SoftwareStatusDeleted, info)
				}
			}
		}()
		info[name].renamed <- true
	} else if ev.IsCreate() {
		self.emitItemChanged(name, SoftwareStatusCreated, info)
		go func() {
			select {
			case <-info[name].renamed:
				// logger.Info("not renamed")
				info[name].notRenamed <- true
				info[name].renamed <- true
			default:
				// logger.Info("default")
			}
			select {
			case <-info[name].notCreated:
				return
			case <-time.After(time.Second):
				<-info[name].created
			}
		}()
		info[name].created <- true
	} else if ev.IsModify() && !ev.IsAttrib() {
		go func() {
			select {
			case <-info[name].created:
				info[name].notCreated <- true
			}
			select {
			case <-info[name].renamed:
				self.emitItemChanged(name, SoftwareStatusModified, info)
			default:
			}
		}()
	} else if ev.IsAttrib() {
		go func() {
			select {
			case <-info[name].renamed:
				<-info[name].created
				info[name].notCreated <- true
			default:
			}
		}()
	} else if ev.IsDelete() {
		if true {
			self.emitItemChanged(name, SoftwareStatusDeleted, info)
		}
	}
}