Skip to content

Commit 5c45dfa

Browse files
committed
internal/oci: Strip leading slashes from tar header
When adding the tar header for the built binary, the leading slashes in the path should be stripped since members within a tar archive should have a relative path. This way, when the tar archive is unpacked in the current directory, or in a different directory when invoked with `tar -C`, the structure within the archive is mirrored outside of the archive. Prior to this commit, if you built an image with gopack, attempted to fetch the individual layer blob from a registry, and print the layer's contents, you would see an error like this: tar: Removing leading `/' from member names /app/gopack-test While GNU tar(1) will strip the leading slashes from member names, it would likely be better to remove the leading slash from the member name entirely when the header is written. After using gopack with this patch applied, attempting to list the archive members from the retrieved layer/blob, the tar warning goes away. Signed-off-by: Nick Saika <[email protected]>
1 parent e772e91 commit 5c45dfa

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

internal/oci/build.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"os"
2424
"path/filepath"
25+
"strings"
2526

2627
v1 "github.com/google/go-containerregistry/pkg/v1"
2728
"github.com/google/go-containerregistry/pkg/v1/mutate"
@@ -106,7 +107,7 @@ func tarGoBin(goBinPath, entrypoint string) ([]byte, error) {
106107

107108
err = tw.WriteHeader(&tar.Header{
108109
Mode: 0555,
109-
Name: entrypoint,
110+
Name: strings.TrimPrefix(entrypoint, "/"),
110111
Size: stat.Size(),
111112
Typeflag: tar.TypeReg,
112113
})

0 commit comments

Comments
 (0)