diff --git a/pkg/skaffold/util/util.go b/pkg/skaffold/util/util.go index 63c6361ea01..64bd9cbb48b 100644 --- a/pkg/skaffold/util/util.go +++ b/pkg/skaffold/util/util.go @@ -267,14 +267,18 @@ func AbsolutePaths(workspace string, paths []string) []string { func IsFile(path string) bool { info, err := os.Stat(path) - // err could be permission-related - return (err == nil || !os.IsNotExist(err)) && info.Mode().IsRegular() + if err != nil { + return false + } + return info.Mode().IsRegular() } func IsDir(path string) bool { info, err := os.Stat(path) - // err could be permission-related - return (err == nil || !os.IsNotExist(err)) && info.IsDir() + if err != nil { + return false + } + return info.IsDir() } // IsEmptyDir returns true for empty directories otherwise false diff --git a/pkg/skaffold/util/util_test.go b/pkg/skaffold/util/util_test.go index 6ac11a639a4..fa308f6e0b4 100644 --- a/pkg/skaffold/util/util_test.go +++ b/pkg/skaffold/util/util_test.go @@ -437,6 +437,14 @@ func TestIsFileIsDir(t *testing.T) { testutil.CheckDeepEqual(t, false, IsDir(filepath.Join(tmpDir.Root(), "nonexistent"))) } +func TestIsFileIsDirStatError(t *testing.T) { + tmpDir := testutil.NewTempDir(t).Touch("file") + pathWithFileAsDir := tmpDir.Path("file/child") + + testutil.CheckDeepEqual(t, false, IsFile(pathWithFileAsDir)) + testutil.CheckDeepEqual(t, false, IsDir(pathWithFileAsDir)) +} + func TestIsURL(t *testing.T) { testutil.CheckDeepEqual(t, false, IsURL("foo")) testutil.CheckDeepEqual(t, false, IsURL("http:bar"))