cmd/pkg: Fix symlink handling in pkg build context

When building the build context, symlink need special
treatment as the link name needs to be added when
building the tar.FileInfoHeader. This code does that.

We may also need to add a special case for hard links
as the moby/moby package 'archive' does, but this
should for now
fixes #3142

Signed-off-by: Rolf Neugebauer <rn@rneugeba.io>
This commit is contained in:
Rolf Neugebauer
2018-07-27 18:39:08 +01:00
parent 26ae9a0246
commit 23555494fe

View File

@@ -222,7 +222,16 @@ func (c *buildCtx) Copy(w io.WriteCloser) error {
return fmt.Errorf("ctx: Walk error on %s: %v", p, err)
}
h, err := tar.FileInfoHeader(i, "")
var link string
if i.Mode()&os.ModeSymlink != 0 {
var err error
link, err = os.Readlink(p)
if err != nil {
return fmt.Errorf("ctx: Failed to read symlink %s: %v", p, err)
}
}
h, err := tar.FileInfoHeader(i, link)
if err != nil {
return fmt.Errorf("ctx: Converting FileInfo for %s: %v", p, err)
}