Merge pull request #1113 from tejal29/add_better_error
fix resolve link for dirs with trailing /
This commit is contained in:
commit
861c039c8f
|
|
@ -67,7 +67,7 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu
|
||||||
fullPath := filepath.Join(c.buildcontext, src)
|
fullPath := filepath.Join(c.buildcontext, src)
|
||||||
fi, err := os.Lstat(fullPath)
|
fi, err := os.Lstat(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "could not copy source")
|
||||||
}
|
}
|
||||||
if fi.IsDir() && !strings.HasSuffix(fullPath, string(os.PathSeparator)) {
|
if fi.IsDir() && !strings.HasSuffix(fullPath, string(os.PathSeparator)) {
|
||||||
fullPath += "/"
|
fullPath += "/"
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCompositeCache returns an initialized composite cache object.
|
// NewCompositeCache returns an initialized composite cache object.
|
||||||
|
|
@ -58,7 +59,7 @@ func (s *CompositeCache) AddPath(p, context string) error {
|
||||||
sha := sha256.New()
|
sha := sha256.New()
|
||||||
fi, err := os.Lstat(p)
|
fi, err := os.Lstat(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "could not add path")
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.Mode().IsDir() {
|
if fi.Mode().IsDir() {
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ func resolveSymlinkAncestor(path string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
last := ""
|
last := ""
|
||||||
newPath := path
|
newPath := filepath.Clean(path)
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for newPath != "/" {
|
for newPath != "/" {
|
||||||
|
|
@ -149,7 +149,6 @@ loop:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if target != newPath {
|
if target != newPath {
|
||||||
last = filepath.Base(newPath)
|
last = filepath.Base(newPath)
|
||||||
newPath = filepath.Dir(newPath)
|
newPath = filepath.Dir(newPath)
|
||||||
|
|
@ -158,7 +157,6 @@ loop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newPath = filepath.Join(newPath, last)
|
newPath = filepath.Join(newPath, last)
|
||||||
return filepath.Clean(newPath), nil
|
return filepath.Clean(newPath), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
package filesystem
|
package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"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) {
|
t.Run("path is a dead symlink", func(t *testing.T) {
|
||||||
testDir, targetPath := setupDirs(t)
|
testDir, targetPath := setupDirs(t)
|
||||||
defer os.RemoveAll(testDir)
|
defer os.RemoveAll(testDir)
|
||||||
|
|
|
||||||
|
|
@ -577,8 +577,7 @@ func CopyDir(src, dest, buildcontext string, uid, gid int64) ([]string, error) {
|
||||||
fullPath := filepath.Join(src, file)
|
fullPath := filepath.Join(src, file)
|
||||||
fi, err := os.Lstat(fullPath)
|
fi, err := os.Lstat(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(" i am returning from here this", err)
|
return nil, errors.Wrap(err, "copying dir")
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
if ExcludeFile(fullPath, buildcontext) {
|
if ExcludeFile(fullPath, buildcontext) {
|
||||||
logrus.Debugf("%s found in .dockerignore, ignoring", src)
|
logrus.Debugf("%s found in .dockerignore, ignoring", src)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue