Merge pull request #2403 from monopole/removeGuess

Remove time guessing.
This commit is contained in:
Jeff Regan
2020-04-22 13:30:09 -07:00
committed by GitHub
2 changed files with 18 additions and 6 deletions

View File

@@ -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()

View File

@@ -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
}