IsUpToDate implements the Checker interface
(t *ast.Task)
| 24 | |
| 25 | // IsUpToDate implements the Checker interface |
| 26 | func (checker *TimestampChecker) IsUpToDate(t *ast.Task) (bool, error) { |
| 27 | if len(t.Sources) == 0 { |
| 28 | return false, nil |
| 29 | } |
| 30 | |
| 31 | sources, err := Globs(t.Dir, t.Sources, t.ShouldUseGitignore()) |
| 32 | if err != nil { |
| 33 | return false, nil |
| 34 | } |
| 35 | |
| 36 | // If generates are declared, ensure they all exist. A missing generated |
| 37 | // file means the task must run regardless of timestamps. |
| 38 | if len(t.Generates) > 0 { |
| 39 | for _, g := range t.Generates { |
| 40 | // Exclusion patterns don't represent output files; skip them. |
| 41 | if g.Negate { |
| 42 | continue |
| 43 | } |
| 44 | files, err := glob(t.Dir, g.Glob) |
| 45 | if os.IsNotExist(err) { |
| 46 | return false, nil |
| 47 | } |
| 48 | if err != nil { |
| 49 | return false, err |
| 50 | } |
| 51 | if len(files) == 0 { |
| 52 | return false, nil |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | generates, err := Globs(t.Dir, t.Generates, t.ShouldUseGitignore()) |
| 58 | if err != nil { |
| 59 | return false, nil |
| 60 | } |
| 61 | |
| 62 | timestampFile := checker.timestampFilePath(t) |
| 63 | |
| 64 | // If the file exists, add the file path to the generates. |
| 65 | // If the generate file is old, the task will be executed. |
| 66 | _, err = os.Stat(timestampFile) |
| 67 | if err == nil { |
| 68 | generates = append(generates, timestampFile) |
| 69 | } else { |
| 70 | // Create the timestamp file for the next execution when the file does not exist. |
| 71 | if !checker.dry { |
| 72 | if err := os.MkdirAll(filepath.Dir(timestampFile), 0o755); err != nil { |
| 73 | return false, err |
| 74 | } |
| 75 | f, err := os.Create(timestampFile) |
| 76 | if err != nil { |
| 77 | return false, err |
| 78 | } |
| 79 | f.Close() |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | taskTime := time.Now() |
nothing calls this directly
no test coverage detected