From 540e458b16ea772a80a293c4072aec14d3efec0e Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 4 Jun 2017 16:45:34 -0300 Subject: [PATCH] refactor isUpToDate() --- task.go | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/task.go b/task.go index d3903477..d887e8cd 100644 --- a/task.go +++ b/task.go @@ -132,25 +132,32 @@ func (e *Executor) runDeps(ctx context.Context, task string) error { func (t *Task) isUpToDate(ctx context.Context) (bool, error) { if len(t.Status) > 0 { - environ, err := t.getEnviron() - if err != nil { - return false, err - } + return t.isUpToDateStatus(ctx) + } + return t.isUpToDateTimestamp(ctx) +} - for _, s := range t.Status { - err = execext.RunCommand(&execext.RunCommandOptions{ - Context: ctx, - Command: s, - Dir: t.Dir, - Env: environ, - }) - if err != nil { - return false, nil - } - } - return true, nil +func (t *Task) isUpToDateStatus(ctx context.Context) (bool, error) { + environ, err := t.getEnviron() + if err != nil { + return false, err } + for _, s := range t.Status { + err = execext.RunCommand(&execext.RunCommandOptions{ + Context: ctx, + Command: s, + Dir: t.Dir, + Env: environ, + }) + if err != nil { + return false, nil + } + } + return true, nil +} + +func (t *Task) isUpToDateTimestamp(ctx context.Context) (bool, error) { if len(t.Sources) == 0 || len(t.Generates) == 0 { return false, nil }