Skip to content

Commit

Permalink
Merge pull request #712 from tonistiigi/clean-readlink
Browse files Browse the repository at this point in the history
contenthash: clean readlink value
  • Loading branch information
AkihiroSuda authored Oct 31, 2018
2 parents 0f8d630 + 5fa4642 commit fba893e
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 fba893e

Please sign in to comment.