@@ -34,38 +34,46 @@ func (t *Timestamp) IsUpToDate() (bool, error) {
3434
3535 timestampFile := t .timestampFilePath ()
3636
37- // if the file exists, add the file path to the generates
38- // if the generate file is old, the task will be executed
37+ // If the file exists, add the file path to the generates.
38+ // If the generate file is old, the task will be executed.
3939 _ , err = os .Stat (timestampFile )
4040 if err == nil {
4141 generates = append (generates , timestampFile )
4242 } else {
43- // create the timestamp file for the next execution when the file does not exist
43+ // Create the timestamp file for the next execution when the file does not exist.
4444 if ! t .Dry {
45- _ = os .MkdirAll (filepath .Dir (timestampFile ), 0o755 )
46- _ , _ = os .Create (timestampFile )
45+ if err := os .MkdirAll (filepath .Dir (timestampFile ), 0o755 ); err != nil {
46+ return false , err
47+ }
48+ f , err := os .Create (timestampFile )
49+ if err != nil {
50+ return false , err
51+ }
52+ f .Close ()
4753 }
4854 }
4955
5056 taskTime := time .Now ()
5157
52- // compare the time of the generates and sources. If the generates are old, the task will be executed
58+ // Compare the time of the generates and sources. If the generates are old, the task will be executed.
5359
54- // get the max time of the generates
60+ // Get the max time of the generates.
5561 generateMaxTime , err := getMaxTime (generates ... )
5662 if err != nil || generateMaxTime .IsZero () {
5763 return false , nil
5864 }
5965
60- // check if any of the source files is newer than the max time of the generates
66+ // Check if any of the source files is newer than the max time of the generates.
6167 shouldUpdate , err := anyFileNewerThan (sources , generateMaxTime )
6268 if err != nil {
6369 return false , nil
6470 }
6571
66- // modify the metadata of the file to the the current time
72+ // Modify the metadata of the file to the the current time.
6773 if ! t .Dry {
68- _ = os .Chtimes (timestampFile , taskTime , taskTime )
74+ if err := os .Chtimes (timestampFile , taskTime , taskTime ); err != nil {
75+ return false , err
76+ }
6977 }
7078
7179 return ! shouldUpdate , nil
@@ -106,8 +114,15 @@ func getMaxTime(files ...string) (time.Time, error) {
106114 return t , nil
107115}
108116
109- // if the modification time of any of the files is newer than the the given time, returns true
110- // This function is lazy, as it stops when it finds a file newer than the given time
117+ func maxTime (a , b time.Time ) time.Time {
118+ if a .After (b ) {
119+ return a
120+ }
121+ return b
122+ }
123+
124+ // If the modification time of any of the files is newer than the the given time, returns true.
125+ // This function is lazy, as it stops when it finds a file newer than the given time.
111126func anyFileNewerThan (files []string , givenTime time.Time ) (bool , error ) {
112127 for _ , f := range files {
113128 info , err := os .Stat (f )
@@ -121,18 +136,11 @@ func anyFileNewerThan(files []string, givenTime time.Time) (bool, error) {
121136 return false , nil
122137}
123138
124- func maxTime (a , b time.Time ) time.Time {
125- if a .After (b ) {
126- return a
127- }
128- return b
129- }
130-
131139// OnError implements the Checker interface
132140func (* Timestamp ) OnError () error {
133141 return nil
134142}
135143
136144func (t * Timestamp ) timestampFilePath () string {
137- return filepath .Join (t .TempDir , "timestamp" , NormalizeFilename (t .Task ))
145+ return filepath .Join (t .TempDir , "timestamp" , normalizeFilename (t .Task ))
138146}
0 commit comments