diff --git a/api/internal/plugins/compiler/compiler_test.go b/api/internal/plugins/compiler/compiler_test.go index 89640f7b1..36f4031cb 100644 --- a/api/internal/plugins/compiler/compiler_test.go +++ b/api/internal/plugins/compiler/compiler_test.go @@ -6,7 +6,6 @@ package compiler_test import ( "path/filepath" "testing" - "time" "sigs.k8s.io/kustomize/api/filesys" . "sigs.k8s.io/kustomize/api/internal/plugins/compiler" @@ -30,7 +29,7 @@ func TestCompiler(t *testing.T) { if err != nil { t.Error(err) } - if !FileYoungerThan(expectObj, time.Second) { + if !FileExists(expectObj) { t.Errorf("didn't find expected obj file %s", expectObj) } c.Cleanup() @@ -49,7 +48,7 @@ func TestCompiler(t *testing.T) { if err != nil { t.Error(err) } - if !FileYoungerThan(expectObj, time.Second) { + if !FileExists(expectObj) { t.Errorf("didn't find expected obj file %s", expectObj) } c.Cleanup() diff --git a/api/internal/plugins/compiler/utils.go b/api/internal/plugins/compiler/utils.go index d117184ff..40bde9e96 100644 --- a/api/internal/plugins/compiler/utils.go +++ b/api/internal/plugins/compiler/utils.go @@ -81,7 +81,8 @@ func DeterminePluginSrcRoot(fSys filesys.FileSystem) (string, error) { }) } -// FileYoungerThan returns true if the file age is <= the Duration argument. +// FileYoungerThan returns true if the file both exists and has an +// age is <= the Duration argument. func FileYoungerThan(path string, d time.Duration) bool { fi, err := os.Stat(path) if err != nil { @@ -92,8 +93,20 @@ func FileYoungerThan(path string, d time.Duration) bool { return time.Since(fi.ModTime()) <= d } -func FileExists(name string) bool { - if _, err := os.Stat(name); err != nil { +// FileModifiedAfter returns true if the file both exists and was +// modified after the given time.. +func FileModifiedAfter(path string, t time.Time) bool { + fi, err := os.Stat(path) + if err != nil { + if os.IsNotExist(err) { + return false + } + } + return fi.ModTime().After(t) +} + +func FileExists(path string) bool { + if _, err := os.Stat(path); err != nil { if os.IsNotExist(err) { return false }