1
0
mirror of https://github.com/go-task/task.git synced 2025-03-05 15:05:42 +02:00

fix: only rewrite checksum files if the checksum has changed

This commit is contained in:
Andrew Berry 2023-06-03 18:20:08 -04:00 committed by GitHub
parent 1936142042
commit 082cdcc358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -42,7 +42,7 @@ func (checker *ChecksumChecker) IsUpToDate(t *taskfile.Task) (bool, error) {
return false, nil
}
if !checker.dry {
if !checker.dry && oldMd5 != newMd5 {
_ = os.MkdirAll(filepathext.SmartJoin(checker.tempDir, "checksum"), 0o755)
if err = os.WriteFile(checksumFile, []byte(newMd5+"\n"), 0o644); err != nil {
return false, err

View File

@ -508,9 +508,10 @@ func TestStatusChecksum(t *testing.T) {
}
var buff bytes.Buffer
tempdir := filepathext.SmartJoin(dir, ".task")
e := task.Executor{
Dir: dir,
TempDir: filepathext.SmartJoin(dir, ".task"),
TempDir: tempdir,
Stdout: &buff,
Stderr: &buff,
}
@ -522,9 +523,19 @@ func TestStatusChecksum(t *testing.T) {
require.NoError(t, err)
}
// Capture the modification time, so we can ensure the checksum file
// is not regenerated when the hash hasn't changed.
s, err := os.Stat(filepathext.SmartJoin(tempdir, "checksum/"+test.task))
require.NoError(t, err)
time := s.ModTime()
buff.Reset()
require.NoError(t, e.Run(context.Background(), taskfile.Call{Task: test.task}))
assert.Equal(t, `task: Task "`+test.task+`" is up to date`+"\n", buff.String())
s, err = os.Stat(filepathext.SmartJoin(tempdir, "checksum/"+test.task))
require.NoError(t, err)
assert.Equal(t, time, s.ModTime())
})
}
}