Merge pull request #1770 from kolyshkin/fix-archive-detection
Fix archive detection
This commit is contained in:
commit
f40f9c240a
@ -89,7 +89,7 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
|
||||
func DetectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, isArchive bool, err error) {
|
||||
buf := bufio.NewReader(input)
|
||||
|
||||
magic, err := buf.Peek(archiveHeaderSize)
|
||||
magic, err := buf.Peek(archiveHeaderSize * 2)
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, false, errors.Errorf("failed to peek context header from STDIN: %v", err)
|
||||
}
|
||||
|
@ -297,3 +297,36 @@ func TestIsArchive(t *testing.T) {
|
||||
assert.Check(t, is.Equal(testcase.expected, IsArchive(testcase.header)), testcase.doc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectArchiveReader(t *testing.T) {
|
||||
var testcases = []struct {
|
||||
file string
|
||||
desc string
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
file: "../testdata/tar.test",
|
||||
desc: "tar file without pax headers",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
file: "../testdata/gittar.test",
|
||||
desc: "tar file with pax headers",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
file: "../testdata/Dockerfile.test",
|
||||
desc: "not a tar file",
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
for _, testcase := range testcases {
|
||||
content, err := os.Open(testcase.file)
|
||||
assert.NilError(t, err)
|
||||
defer content.Close()
|
||||
|
||||
_, isArchive, err := DetectArchiveReader(content)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(testcase.expected, isArchive), testcase.file)
|
||||
}
|
||||
}
|
||||
|
3
cli/command/image/testdata/Dockerfile.test
vendored
Normal file
3
cli/command/image/testdata/Dockerfile.test
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
FROM busybox
|
||||
ADD ./README.md /
|
||||
CMD ["cat", "/README.md"]
|
BIN
cli/command/image/testdata/gittar.test
vendored
Normal file
BIN
cli/command/image/testdata/gittar.test
vendored
Normal file
Binary file not shown.
BIN
cli/command/image/testdata/tar.test
vendored
Normal file
BIN
cli/command/image/testdata/tar.test
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user