Break out of infinite config loops

This commit is contained in:
Alex Yatskov 2015-04-09 19:29:25 +09:00
parent cccb9b3903
commit 51513b24a2
2 changed files with 14 additions and 4 deletions

View File

@ -26,13 +26,16 @@ import "fmt"
type config struct { type config struct {
Tasks map[string]task Tasks map[string]task
tasksHandled map[string]bool
} }
func (this *config) process(srcDir, dstDir, taskName string, flags int) error { func (this *config) process(srcDir, dstDir, taskName string, flags int) error {
this.tasksHandled = make(map[string]bool)
task, ok := this.Tasks[taskName] task, ok := this.Tasks[taskName]
if !ok { if !ok {
return fmt.Errorf("task not found %s", taskName) return fmt.Errorf("task not found %s", taskName)
} }
return task.process(srcDir, dstDir, this, flags) return task.process(taskName, srcDir, dstDir, this, flags)
} }

11
task.go
View File

@ -30,14 +30,21 @@ type task struct {
Cmds []command Cmds []command
} }
func (this *task) process(srcDir, dstDir string, conf *config, flags int) error { func (this *task) process(taskName, srcDir, dstDir string, conf *config, flags int) error {
handled, ok := conf.tasksHandled[taskName]
if ok && handled {
return nil
}
conf.tasksHandled[taskName] = true
for _, depName := range this.Deps { for _, depName := range this.Deps {
depTask, ok := conf.Tasks[depName] depTask, ok := conf.Tasks[depName]
if !ok { if !ok {
return fmt.Errorf("task dependency not found %s", depName) return fmt.Errorf("task dependency not found %s", depName)
} }
if err := depTask.process(srcDir, dstDir, conf, flags); err != nil { if err := depTask.process(depName, srcDir, dstDir, conf, flags); err != nil {
return err return err
} }
} }