From c75749b840dffb83e56ce48a0a75c2aec2a80397 Mon Sep 17 00:00:00 2001 From: xanonid Date: Mon, 29 Jul 2019 20:07:31 +0200 Subject: [PATCH] Do not use leading slashes for paths in layer tarballs to be more compatible with docker --- pkg/util/tar_util.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/util/tar_util.go b/pkg/util/tar_util.go index bc1cc67a0..f358f48ad 100644 --- a/pkg/util/tar_util.go +++ b/pkg/util/tar_util.go @@ -25,6 +25,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "syscall" "github.com/docker/docker/pkg/archive" @@ -74,7 +75,14 @@ func (t *Tar) AddFileToTar(p string) error { if err != nil { return err } - hdr.Name = p + + if p != "/" { + // Docker uses no leading / in the tarball + hdr.Name = strings.TrimLeft(p, "/") + } else { + // allow entry for / to preserve permission changes etc. (currently ignored anyway by Docker runtime) + hdr.Name = p + } hardlink, linkDst := t.checkHardlink(p, i) if hardlink {