MCPcopy
hub / github.com/go-task/task / IsUpToDate

Method IsUpToDate

internal/fingerprint/sources_timestamp.go:26–107  ·  view source on GitHub ↗

IsUpToDate implements the Checker interface

(t *ast.Task)

Source from the content-addressed store, hash-verified

24
25// IsUpToDate implements the Checker interface
26func (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()

Callers

nothing calls this directly

Calls 8

timestampFilePathMethod · 0.95
GlobsFunction · 0.85
globFunction · 0.85
getMaxTimeFunction · 0.85
anyFileNewerThanFunction · 0.85
ShouldUseGitignoreMethod · 0.80
CloseMethod · 0.80
DirMethod · 0.65

Tested by

no test coverage detected