mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Merge pull request #2403 from monopole/removeGuess
Remove time guessing.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user