Skip to content

Commit

Permalink
contenthash: clean readlink value
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Oct 31, 2018
1 parent 91cd9b4 commit 5fa4642
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cache/contenthash/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func getFollowLinksWalk(root *iradix.Node, k []byte, linksWalked *int) ([]byte,
if dirPath == "." || dirPath == "/" {
dirPath = ""
}
link := parent.Linkname
link := path.Clean(parent.Linkname)
if !path.IsAbs(link) {
link = path.Join("/", path.Join(path.Dir(dirPath), link))
}
Expand Down
27 changes: 27 additions & 0 deletions cache/contenthash/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,33 @@ func TestSymlinkNeedsScan(t *testing.T) {
require.NoError(t, err)
}

func TestSymlinkAbsDirSuffix(t *testing.T) {
t.Parallel()
tmpdir, err := ioutil.TempDir("", "buildkit-state")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)

snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
cm := setupCacheManager(t, tmpdir, snapshotter)
defer cm.Close()

ch := []string{
"ADD c0 dir",
"ADD c0/sub dir",
"ADD c0/sub/foo file data0",
"ADD link symlink /c0/sub/",
}
ref := createRef(t, cm, ch)

dgst, err := Checksum(context.TODO(), ref, "link/foo")
require.NoError(t, err)
require.Equal(t, dgstFileData0, dgst)

err = ref.Release(context.TODO())
require.NoError(t, err)
}

func TestSymlinkInPathHandleChange(t *testing.T) {
t.Parallel()
tmpdir, err := ioutil.TempDir("", "buildkit-state")
Expand Down

0 comments on commit 5fa4642

Please sign in to comment.