Exemplo n.º 1
0
func execParent() {
	listener := watcher.NewListener()
	listener.Path = RootPath
	listener.DebounceDuration = 100 * time.Millisecond
	listener.IgnorePart = deletePart
	listener.IgnoreSuffix = deleteSuffix
	listener.IgnoreSubstring = deleteSubstring
	listener.NotifyDirectoriesOnStartup = true
	err := listener.Start()
	if err != nil {
		alog.Printf("@(error:Error starting watcher for %s: %v)\n", RootPath, err)
	}
	go readPathUpdates(listener.NotifyChan)
	go handleParentMessages()
	go sendKeepAlives()
}
Exemplo n.º 2
0
Arquivo: util.go Projeto: tillberg/gut
func (ctx *SyncContext) watchForChangesLocal(fileEventCallback func(string)) {
	status := ctx.NewLogger("watcher")
	listener := watcher.NewListener()
	listener.Path = ctx.syncPath
	listener.IgnorePart = stringset.New(".gut")
	err := listener.Start()
	status.BailIf(err)

	go func() {
		for pathEvent := range listener.NotifyChan {
			path := pathEvent.Path
			relPath, err := filepath.Rel(ctx.syncPath, path)
			if err != nil {
				status.Bail(err)
			}
			fileEventCallback(relPath)
		}
	}()
}
Exemplo n.º 3
0
func main() {
	sighup := autorestart.NotifyOnSighup()
	_, err := flags.ParseArgs(&Opts, os.Args)
	if err != nil {
		err2, ok := err.(*flags.Error)
		if ok && err2.Type == flags.ErrHelp {
			return
		}
		alog.Printf("Error parsing command-line options: %s\n", err)
		return
	}
	if goPath == "" {
		alog.Printf("GOPATH is not set in the environment. Please set GOPATH first, then retry.\n")
		alog.Printf("For help setting GOPATH, see https://golang.org/doc/code.html\n")
		return
	}
	if Opts.NoColor {
		alog.DisableColor()
	} else {
		alog.AddAnsiColorCode("time", alog.ColorBlue)
	}
	alog.Printf("@(dim:autoinstall started.)\n")
	if Opts.MaxWorkers == 0 {
		Opts.MaxWorkers = runtime.GOMAXPROCS(0)
	}
	pluralProcess := ""
	if Opts.MaxWorkers != 1 {
		pluralProcess = "es"
	}
	alog.Printf("@(dim:Building all packages in) @(dim,cyan:%s)@(dim: using up to )@(dim,cyan:%d)@(dim: process%s.)\n", goPath, Opts.MaxWorkers, pluralProcess)
	if !Opts.Verbose {
		alog.Printf("@(dim:Use) --verbose @(dim:to show all messages during startup.)\n")
	}

	listener := watcher.NewListener()
	listener.Path = srcRoot
	// "_workspace" is a kludge to avoid recursing into Godeps workspaces
	// "node_modules" is a kludge to avoid walking into typically-huge node_modules trees
	listener.IgnorePart = stringset.New(".git", ".hg", "node_modules", "_workspace", "etld")
	listener.NotifyOnStartup = true
	listener.DebounceDuration = 200 * time.Millisecond
	listener.Start()

	// Delete any straggler tmp files, carefully
	files, err := ioutil.ReadDir(tmpdir)
	if err == nil {
		for _, file := range files {
			if filepath.Ext(file.Name()) == ".tmp" {
				os.Remove(filepath.Join(tmpdir, file.Name()))
			}
		}
	} else if os.IsNotExist(err) {
		err = os.MkdirAll(tmpdir, 0700)
		if err != nil {
			alog.Printf("@(error:Error creating temp directory at %s: %v)\n", tmpdir, err)
			return
		}
	} else {
		alog.Printf("@(error:Error checking contents of temp directory at %s: %v)\n", tmpdir, err)
		return
	}

	go processPathTriggers(listener.NotifyChan)
	go dispatcher()

	<-sighup
	startupLogger.Close()
}