Exemplo n.º 1
0
func findFiles(path string, depth int, skips []*regexp.Regexp) ([]string, error) {
	baseNumSeps := strings.Count(path, string(os.PathSeparator))
	var files []string
	err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			log.Warnf("filewalk: %s", err)
			return nil
		}
		if info.IsDir() {
			pathDepth := strings.Count(path, string(os.PathSeparator)) - baseNumSeps
			if pathDepth > depth {
				return filepath.SkipDir
			}
		}
		name := info.Name()
		isSkip := false
		for _, skip := range skips {
			if skip.MatchString(name) {
				isSkip = true
				break
			}
		}
		// log.Println(isSkip, name)
		if !isSkip {
			files = append(files, path)
		}
		if isSkip && info.IsDir() {
			return filepath.SkipDir
		}
		return nil
	})
	return files, err
}
Exemplo n.º 2
0
func (this *gowatch) drainExec() {
	log.Println("command:", this.Command)
	var msg string
	for {
		startTime := time.Now()
		cmd := this.Command
		if len(cmd) == 0 {
			cmd = []string{"echo", "no command specified"}
		}
		colorPrintf("35", "exec start")
		c := StartCmd(cmd[0], cmd[1:]...)
		err := c.Start()
		if err != nil {
			colorPrintf("35", err.Error())
		}
		select {
		case msg = <-this.sig:
			colorPrintf("33", "program terminated, signal(%s)", this.KillSignal)
			if err := KillCmd(c, this.KillSignal); err != nil {
				log.Errorf("group kill: %v", err)
			}
			if msg == "EXIT" {
				os.Exit(1)
			}
			goto SKIP_WAITING
		case err = <-Go(c.Wait):
			if err != nil {
				log.Warnf("program exited: %v", err)
			}
		}
		log.Infof("finish in %s", time.Since(startTime))
		if this.AutoRestart {
			goto SKIP_WAITING
		}
		colorPrintf("33", "-- wait signal --")
		if msg = <-this.sig; msg == "EXIT" {
			os.Exit(1)
		}
	SKIP_WAITING:
		if this.RestartInterval > 0 {
			log.Infof("restart after %s", this.RestartInterval)
		}
		time.Sleep(this.RestartInterval)
	}
}
Exemplo n.º 3
0
func (this *gowatch) drainEvent() {
	for {
		select {
		case err := <-this.w.Error:
			log.Warnf("watch error: %s", err)
		case <-this.sigOS:
			this.sig <- "EXIT"
		case eve := <-this.w.Event:
			log.Debug(eve)
			changed := this.IsfileChanged(eve.Name)
			if changed && this.match(eve.Name) {
				log.Info(eve)
				select {
				case this.sig <- "KILL":
				default:
				}
			}
		}
	}
}
Exemplo n.º 4
0
func init() {
	if _, err := ReadPkgConfig(RCFILE); err != nil {
		log.Warnf("Read %s err: %v", RCFILE, err)
	}
}