diff --git a/pkg/commands/copy.go b/pkg/commands/copy.go index 31cb61f5a..c4102ef81 100644 --- a/pkg/commands/copy.go +++ b/pkg/commands/copy.go @@ -67,7 +67,7 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu fullPath := filepath.Join(c.buildcontext, src) fi, err := os.Lstat(fullPath) if err != nil { - return err + return errors.Wrap(err, "could not copy source") } if fi.IsDir() && !strings.HasSuffix(fullPath, string(os.PathSeparator)) { fullPath += "/" diff --git a/pkg/executor/composite_cache.go b/pkg/executor/composite_cache.go index df1eb5ef8..d8ebfda94 100644 --- a/pkg/executor/composite_cache.go +++ b/pkg/executor/composite_cache.go @@ -24,6 +24,7 @@ import ( "strings" "github.com/GoogleContainerTools/kaniko/pkg/util" + "github.com/pkg/errors" ) // NewCompositeCache returns an initialized composite cache object. @@ -58,7 +59,7 @@ func (s *CompositeCache) AddPath(p, context string) error { sha := sha256.New() fi, err := os.Lstat(p) if err != nil { - return err + return errors.Wrap(err, "could not add path") } if fi.Mode().IsDir() { diff --git a/pkg/filesystem/resolve.go b/pkg/filesystem/resolve.go index 2fc869555..63beff748 100644 --- a/pkg/filesystem/resolve.go +++ b/pkg/filesystem/resolve.go @@ -127,7 +127,7 @@ func resolveSymlinkAncestor(path string) (string, error) { } last := "" - newPath := path + newPath := filepath.Clean(path) loop: for newPath != "/" { @@ -149,7 +149,6 @@ loop: if err != nil { return "", err } - if target != newPath { last = filepath.Base(newPath) newPath = filepath.Dir(newPath) @@ -158,7 +157,6 @@ loop: } } } - newPath = filepath.Join(newPath, last) return filepath.Clean(newPath), nil } diff --git a/pkg/filesystem/resolve_test.go b/pkg/filesystem/resolve_test.go index c785ebb52..af402a86e 100644 --- a/pkg/filesystem/resolve_test.go +++ b/pkg/filesystem/resolve_test.go @@ -17,6 +17,7 @@ limitations under the License. package filesystem import ( + "fmt" "io/ioutil" "os" "path/filepath" @@ -234,6 +235,27 @@ func Test_resolveSymlinkAncestor(t *testing.T) { } }) + t.Run("dir ends with / is not a symlink", func(t *testing.T) { + testDir, _ := setupDirs(t) + defer os.RemoveAll(testDir) + + linkDir := filepath.Join(testDir, "var", "www") + if err := os.MkdirAll(linkDir, 0777); err != nil { + t.Fatal(err) + } + + expected := linkDir + + actual, err := resolveSymlinkAncestor(fmt.Sprintf("%s/", linkDir)) + if err != nil { + t.Errorf("expected err to be nil but was %s", err) + } + + if actual != expected { + t.Errorf("expected result to be %s not %s", expected, actual) + } + }) + t.Run("path is a dead symlink", func(t *testing.T) { testDir, targetPath := setupDirs(t) defer os.RemoveAll(testDir) diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 137d4bb4b..40c705dd8 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -577,8 +577,7 @@ func CopyDir(src, dest, buildcontext string, uid, gid int64) ([]string, error) { fullPath := filepath.Join(src, file) fi, err := os.Lstat(fullPath) if err != nil { - fmt.Println(" i am returning from here this", err) - return nil, err + return nil, errors.Wrap(err, "copying dir") } if ExcludeFile(fullPath, buildcontext) { logrus.Debugf("%s found in .dockerignore, ignoring", src)